note 23334 deleted from function.urlencode by tularis
| From: | tularis@php.net | Date: | Sun, 19 Dec 2004 09:44:53 +0000 |
| Subject: | note 23334 deleted from function.urlencode by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82023@lists.php.net to get a copy of this message | ||
Note Submitter: Webmaster[AT]ReikiMagazine[DOT]com
----
Many examples here on how to convert spaces, but how about converting linefeeds or carriage returns:
I needed a form that also contained a textarea field to add notes if applicable. I used a require()
function for including the form again with all of its data when an error occured, e.g. a required
field was not filled in. This presented a include failure when a return was used in the notes-field.
I had allready translated spaces to + with the str_replace() function, but I couldn't solve
this one. I finally used this trick:
// just before including the form and passing on the values
$notes = urlencode($notes);
$notes = str_replace("%0A","[LF]",$notes); // linefeed converted to
"[LF]"
$notes = str_replace("%0D","[CR]",$notes); // carriage return converted to
"[CR]"
$notes = urldecode($notes);
And now in the form include:
// just before printing the textarea:
$notes = str_replace("[LF]","\n",$notes); // "[LF]" converted back
$notes = str_replace("[CR]","\r",$notes); // "[CR]" converted back
I couldn't find any other way, maybe this is of any help to anyone here. I just assume nobody
ever types [LF] or [CR] in the notes-field.