Function To Strip Returns
I'm trying to write a function that will trim and strip new line
character returns from submitted $_POST values. Does this look serviceable?
function trim_data($formdata)
{
foreach ($formdata as $key => $value)
{
$value = preg_replace("(
|
|
| )", "", $value);
$newdata[trim($key)] = trim($value);
}
return $newdata;
}
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Function Returns Nothing (instead Of Flash)
Hi there, I have a site with just a few pages. (e.g. home.php) In every page there is another page included with things like the header etc. The included file is in a subdirectory called "include". There are two functions written in this included file: ================================================== ========================= function doImage($image) { list($width, $height, $type, $attr) = getimagesize($image); echo "<img src=$image width="$width" height="$height">"; }; function doFlash($Movie,$Height,$Width) { echo "<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="$Height" width="$Width"> <param name="movie" value="$Movie"> <param name="quality" value="high"> <param name="allowscale" value="true"> <param name="SCALE" value="exactfit"> <param name="menu" value="false"> <param name="wmode" value="transparent"> <embed src="$Movie" width="$Width" height="$Height" menu="false" wmode="transparent" allowscale="true" scale="exactfit" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed> </object>"; }; ================================================== ========================= I call the functions from pages in the root directory, pages like home.php... When i call doImage("img/logo.gif"); it works well, but when i call doFlash("swf/logo.swf","100px","100px"); It returns everything before the <html> tag starts, so it isn't in the right place either. When i change the "echo"-statement of doFlash() to "return" nothing happens and it disappears in the source (online) What am i doing wrong?
Function Always Returns 'true'
This is supposed to be a simple function that allows user to change his login name and password. But if the user does not exist in MembersOnly table the function retuns true anyway even though Update didn't execute. PHP Code:
Mail() Function Returns FALSE
I'm having trouble getting sendmail to behave with the php mail() function. The function is returning FALSE. Today it doesn't seem to want to allow mail entered via unix "mail" command either although that worked yesterday (the mail took about an hour to show up!) I suspect it is to do with permissioning. Please can someone show me what permissions to check? sendmail is running as root, httpd as user www. OS is OpenBSD3.3. phpinfo() shows sendmail_from to have no value. Does that matter?
Function That Returns Current Numeric Index?
In reading through the list of array-related functions I did not find on which returns the numeric index where the array's internal pointer currently sits. Is there such a function?
URL Strip
Is there a way to get the URL of a page without actually typing it out and then store that in a variable $url? If so, how can I strip the URL? For example: say the URL is: www.blah.com/ken2k7/page1.php Say I want to get the ken2k7 part and store that into a variable $user, how would I do that? And the URL won't always be that, it can be www.blah.com/newuser/page2.php
Strip
What would you use to strip beta or of beta.wordpress.com trying to make a tag section for wordpress mu and need to strip out the subdomain from the database. Thank you
Strip / Addslashes
Could somebody please explain to me why echo addslashes ( stripslashes ( $stuff ) ); does not output the same thing as echo $stuff; ?
Strip- Vs Addslashes
I must have som errors in my understanding of strip- vs addslashes. I thought that if a user submitted eg a username, like this username=siv' drop database test; I should addslashes to escape ' and " and therefore prohibit the evil user to drop/change my database through sql injection (my example may not be correct, but I believe it points out that evil user can add sql commands through an input field. But - I've been reading lots of code lately, and I see that others use stripslashes insted of addslashes. And my question is why. What did I miss? Has it something to do with gpc_magic_quotes?
How To Strip Punctuation?
I am writing a routine that places words used in search phrases into a database table. I am using "explode" to spearate each keyword into a separate entry, but I would also like to strip all punctuation. Can anyone point me in the right direction? I've been toying with preg_replace, but I can't get the syntax to work.
Strip Bbcode
I've been trying to piece together a function that can strip bbcode/vBcode from a block of text (ie: posts). I don't want to translate any of it - just remove all instances of [ ] and whatever tags are between them. This is probably a simple string parsing application, but I can't seem to figure out a way to pull it off.
Strip HTML, Byt Allow Some
How can I strip all HTML tags, except a few that I set as allowed? (strip_tags() doesn't work, have to validate attributes and that the tag is closed)Anyone have a function that I might use?
Strip Text For Rss
this should be a simple answer but i cant figure out what to use to strip text for use in rss. i keep getting errors because of things like "–"
Strip A Number
I AM getting 111111 as a variable, I want the first 1 of that series. I can not get it to work with substr(), is there anything else I can do?
Strip Tags
I am trying to take external content (text description) that could either be raw text, or HTML content - and assign it to a field that will be displayed on my website. Since I want to present the data on my website, I want to strip the majaority of HTML tags, that control is font, colour, size, underlines etc. I know that PHP provides strip_tags for this purpose. The thing is, I want it to keep the carriage returns/newlines, and if possible bullet points - does anyone know how I can achieve this?
What To Strip From User Input:
I recently suffered massive bot attacks against my contact page. Someone sent me over 350 e-mails from my form in less than a couple of hours. As this form only sends e-mail to an address dedicated for this purpose, this isn't more than an inconvenience. In re-writing it, I decided to write better stripslash and strip_tags functions of my own. I have the function stripping out left and right angle brackets, and forward and back slashes. I replace these with blanks (I am the only one that views these e-mails and I think I can figure out what was meant). That should break most script and malicious html tags. What else should I watch for and strip? I thought it might be wise to replace "=" signs with blanks. Should I worry about words like "query" or "fopen"? Part of my solution to preventing bot attacks against my form is to force manual input by varying the name="" values. I have eighteen different possibilities for each field on the form. I choose which to use randomly. I check each possibility when processing to see if it is set and send posters to a 404 page if they post to the wrong or all possible variables. I also include a random string of 5 digits as an authorization code in a hidden field. I use mysql database to let the processing page know what variables and authorization code to expect, associated with the poster's ip. Use the wrong authorization code and you go to the 404 page. If your ip doesn't show up on in the database, you get a "404 page not found." I delete records from the database after processing, including old, unused entries where someone left without completely filling out the form. Does anyone see any reason that won't work to thwart the bots?
Need To Strip The Slashes Out Of Many Variables...
I need to strip the slashes out of many variables being passed between multiple forms. Unfortunately, one of those variables is an array, so the script was choking on the array to string conversion. To work around this, I coded the script to... (a) copy the array from $_POST into a variable. (b) set the array in $_POST to an empty string. (c) strip the slashes from everything in $_POST and copy to a portable array. (d) copy the variable from (a) into a slot in the portable array from (c). (e) send the portable array on it's way. This worked. No errors. The slashes are gone. The variable and array values are moving. But I'm afraid I'm not experienced enough with PHP to know whether this is a stable/reliable/safe way to handle this situation. Are there easier or better ways to accomplish this using one of PHP's many functions of which I am blissfully unaware? Here's the code for the function. Thanks in advance for any replies. function fetch_postvalues() { $cats = $_POST['cats']; $_POST['cats'] = '' $entry_values = get_magic_quotes_gpc()? array_map('stripslashes', $_POST) : $_POST; $entry_values['cats'] = $cats; return $entry_values; }
Query_string Test And Strip.
Could someone give me the topics to look up on php.net, to be able to work out how to remove stuff added to a query_string? I wish to check $QUERY_STRING, and remove any user added extras.
Strip Last Character Off String
I have the following string: text, text, text, text, I need to strip the last comma from it. Is there a function that pops first and last characters from strings... I was also looking at the strpos() function, but not sure how to use it properly to achieve the desired result...
Strip Links From Html
I want to strip links from various html pages that I enter from a form. I am so far using file_get_contents() to get the info into a string. The part I am confused with is how exactly do I get the link text itself into one string and then the href or url it leads to in another?
Strip Slashes Using This Syntax?
Should be simple question but just want to make sure since i've only used stripslashes in a different manner of output. Here's what I have in mind. This list will be echoed to the browser showing updated information. I'm using mysql_real_escape_string for the insertion of the data and want to strip the slashes for this output: <?php echo "<ul><li>Step 1: stripslashes($step1)</li> <li>Step 2: stripslashes($step2)</li> <li>Step 3: stripslashes($step3)</li> <li>Step 4: stripslashes($step4)</li> <li>Details: stripslashes($details)</li> <li>Extra Pick #1: stripslashes($extra_pick1)</li> <li>Extra Pick #2: stripslashes($extra_pick2)</li> <li>Extra Pick #3: stripslashes($extra_pick3)</li> <li>Extra Pick #4: stripslashes($extra_pick4)</li> </ul><br> "; ?> It looks funky in my PHP editor in regards to the color coding.
Strip Leading Zero's
I have a start time and an end time (of a given event) stored in my db as varchar. So, a 1.30 start time looks like 01.30 in the db. Obviously this echos out as 01.30. How do I strip the leading zero's off? I'm looking at str_replace, but I caan't get it right.
PHP Socket Strip XML Tags?
I have implemented a socket in PHP 5.1 which sends a command to a 3rd Party server. The server responds with some XML data. However the data I receive has had all of the XML tags removed, so that I get all of the data items concatenated together. I have used some socket monitors, and I am, absolutely certain that the correct data is being sent buy the server, it is just not being received properly by PHP. I am using fsockopen ( 127.0.0.1 ) and fgets, but I have also tried fread and it makes no difference. I still only ever get the data part of the XML string without the tags. I have searched the web and not found anything similar. Does any one know what I might be doing wrong??
Strip Margin From P Tags
I want to be able to strip the MARGIN elements from the <P> tags. Currently, I use strip tags to remove the <P> elements completely, but have found that this results in a poorer display of the clients data, since its ignoring paragraphs. What I actually want to do is just ignore the MARGIN settings within the P tags. Does anyone know how I can achieve this?
PHP Strip Slashes In Contact Form
Hello, I've been using the following code for email submissions on my website but I could never figure out how to get rid of the slashes when apostrophes are used, once the email is sent. I did a search on this forum and read a bit about the "stripslash" command, but I couldn't figure out how to implement it with the script that I'm using.
Strip Tags With Contents N Times
What is the best way to delete tags n times from either the beginning or the end of a String? For example, to delete "someString1" and "someString2" along with surrounding <someTag>'s with n=2 and processing direction is from beginning. $someBigString="<someTag>someString1</someTag><someTag>someString2</someTag><someTag>someString3</someTag>"; I was thinking about use preg_replace() to replace "/</tag><tag/" with "" but wasn't sure how, especially about the n times and direction of processing.
Strip Html Tags ATTRIBUTES With Reg Exp
I want to strip html attribute within a tag. e.g.: <td class="blah" colspan="2" bgcolor="#ffffff">blah</td> And I want to leave the 'colspan="2"' intact. result after stripping with reg exp: <td colspan="2">blah</td>
Strip Email Address From Field?
I'm looking for a routine than can find any valid email address in a field and replace it with text. For example if the field was filled with "My email address is foo@foobar.com and I'm ugly" then the routine would change the text to: "My email address is newtext and I'm ugly" Any ideas on how to accomplish this?
Strip Spaces And Change To Hyphen
I have my RSS working @ www.add.ie/rss.php but it's entering a Space instead of a Hypen (-) in the link title of each ad. I have tried sttr str replace etc. etc. How do i strip the spaces from v_title and replace them with a hypen. for ($i = 0; $i < mysql_num_rows($result1); $i++) { @$row = mysql_fetch_array($result1); $title = "".cleanText($row["v_title"]).""; $link = " http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; $description = cleanText($row["v_descr"]);
Strip Out Commas And Characters In A Text Box
I have a form that the user can enter a number in the text field and a calculation is then preformed with PHP when the form is submitted. $amount = $_POST['amount']; <input type="text" name="amount" size="20" value=""> Any way to strip out commas and any characters that may be entered. I would like an entry like $5000, 5000, 5,000 and $5,000 all to be passed on to the PHP script as 5000. The way it is now the php math script treats 5,000 as a 5 and $5000 as a 0.
Strip And Reuse Words Form A Aline
I have tried searching around with no joy. What I am trying to do is as follows: I have a db with a table that has for example the following data in: example 1 - this is example 1 test 2 - test 2 thing 3 - and this is thing 3 Now what I am tryingto do is remove everything from the first word after the "- " to the beggining and then put that data into another variable so I would have: "example 1 - " "test 2 - " "thing 3 - " I am stuck by which command I should be using.
Iconv To Strip Out Specfic Language Characters
I cannot figure out how to use iconv to "normalize" characters specific to some language. I need it in file upload where I take a file from local disc and then save to server and use in web pages, for example, as img source. What should be the second parameter of the function? Say, iconv('ISO-8859-1', 'ASCII//TRANSLIT', $str); works but it gives too much transformed result. I would like just replace specific chars, like "a acute", "a with macron", "a umlaut", with a character without accent.
How To Strip Header Section From An HTML Page?
I have an html page returned from a curl session in a variable. I want to strip off the header portion of the file and replace with a new header. It seemed to me that this is probably a well-known thing to want to do, but before I try to write the code myself, anyone have any code examples of how to do this?
Regular Expression Strip HTML Tags
I'm stripping out the attributes in <TD> tags...but I want to strip out everything BUT the COLSPAN attribute. The following strips out all attributes. What do I do if I want to keep a certain one? eregi_replace("<TD[^>]*>","<TD>", $string);
How To Strip Out Unnecessary Lines From Php Fopen File
I have a file that is stored on a computer on my network which i access using fopen for reading. The localpath to the file is http://www.example.com/output.txt The contents of this file is updated once in a while and basically I need a php script that will open this file, read it and then remove certain things and then save a copy locally. The contents of this file looks as follows: Volume in drive C has no label. Volume Serial Number is A85F-F7AD Directory of C: est 10/01/2007 01:36 PM <DIR> . 10/01/2007 01:36 PM <DIR> .. 10/01/2007 01:32 PM <DIR> abc 10/01/2007 01:32 PM <DIR> 123 10/01/2007 01:32 PM <DIR> def 10/01/2007 01:32 PM <DIR> 456 0 File(s) 0 bytes 7 Dir(s) 68,797,751,296 bytes free i want to get rid of the first 7 lines of the file and the last 3 lines. and then on each line i want to get rid of everything before the <DIR> including the <DIR> aswell.
How To Strip Styles Embedded Within Html Tags?
I'm a complete PHP n00b slowly finding my way around I'm using the following function that I found on php.net to strip out html and return only the text. It works well except for when you find styles embedded within the tags eg: <h3 id="pageName">Have a great day!! </h3> This throws an error, whereas <h3 >Thank you for your purchase! </h3works like a charm. It also falls over when crappy code has <h3> </h3between the tags. What do I need to add to the below function to get it to work on cases like above? The function is: function html2txt($txt){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[/!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![sS]*?--[ ]*>@', // Strip multi-line comments including CDATA "@</?[^>]*>*@" ); $text = preg_replace($search, '', $txt); return $text; }
How To Strip Quotes (single And Double) From A String
I have used a class called clsMetaContent.php, as provided in the book Creating Interactive Websites with PHP and Web Services, by Eric Rosebrock - who I understand is the lead developer of this site. While using this class with my application - I find a problem in the assignment of the description for the description part of the meta tag. The code in the class looks like this: // Formulate the description for each page. if(empty($ptitle)){ $description = $this->description; } else { $description = '$ptitle - $this->description"; I have found that my description can contain single and/or double quotes. Which causes a problem with the assignment of the meta tag for the description. What happens is, due to the error in the format of the meta tad description, it outputs the contents of description again on the start of my web page, instead of keeping it within the meta tag assignment. I think I just need a function to strip out double and single quotes - but have been unable to find any.
Strip HTML Tags, And Save To A Seperate Array
I am trying to take a string, and seperate the HTML code from the string and put it into an array, and then take my string it into several strings of around 110 characters, and then put the HTML back in, does anyone think it can be done, and how?
Strip Comments, Tabs And Spaces From Scripts Prior To Deployment
I write a lot of comments in my PHP scripts, and I use tabs to indent different sections for readability and to keep things tidy. Until now, my scripts have been placed in production environments with all comments and "unnecessary blanks" included. PHP works fast when it comes to parsing big scripts, but I imagine that a little script compression would not hurt at all. What I would like to do, is to keep my source in one directory structure, and generate another parallel directory structure with compressed scripts for deployment to production servers. If anyone knows about existing software for this purpose, I would be glad to hear about it. But then again, making a PHP script to do the job does not seem like a difficult thing to do. Here is what I want it to do to my PHP scripts: 1) Remove comments 2) Remove leading and tailing tabs/spaces on each line 3) Remove blank lines If I read a script file into a string ($content), I can use preg_replace() something like this: Code: // Remove comments $content = preg_replace ("/(//|#).*/m", "", $content); // Trim spaces and tabs $content = preg_replace ("/(^[40 ]+)|([40 ]+$)/m", "", $content); // Remove blank lines $content = preg_replace ("/^[40 12 ]+/m", "", $content); So far this seems to work quite well. I know that formatting text with <PRE> in my scripts will be affected by this compact method, as it removes newline/linefeed from the source code. But I hardly ever use <PRE>, so I can live with that. Does anyone have comments on this method? Can these regular expressions do unexpected things to my PHP-code, leading to either parser errors or unpredicted actions/bugs?
Session_start() Never Returns
I call session_start() for almost every page on my site. After I add a lot of data to a registered session variable session_start() does no return control to the script when it is called. How much data can you store in a session variable? PHP.exe uses 0% of the cpu while the browser just hangs and waits. Have pinpointed the script hanging at session_start() using echo and die.
Returns No Variable
i run the following script, and, it returns no variable, but it should! ============================================= while ($Row = mysql_fetch_array($Query2)) { if ($post[usergroupid] < 4) { if ($Row[rank_2] != "final") { if ( ($post[posts] > $Row[rank_1]) AND ($post[posts] < $Row[rank_2]) ) { $bingbing = "$Row[rank]"; } } else { if ($post[posts] < $Row[rank_1]) { $bingbing = "$Row[rank]"; } } } else { $bingbing = "$post[usertitle]"; } } ============================================= now, $Row[rank_1] is 30.$Row[rank_2] is 50.. $post[posts] is 43.. and the $post[usergroupid] is 2. so can someone tell me why its not working?
|