note 23334 added to function.urlencode
| From: | Webmaster@php.net | Date: | Mon, 15 Jul 2002 19:37:28 +0000 |
| Subject: | note 23334 added to function.urlencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33104@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/function.urlencode.php
http://master.php.net/manage/user-notes.php?action=edit+23334
http://master.php.net/manage/user-notes.php?action=delete+23334
http://master.php.net/manage/user-notes.php?action=reject+23334