note 32960 added to function.str-replace
| From: | kieran at lv6 dot net | Date: | Wed, 11 Jun 2003 23:55:16 +0000 |
| Subject: | note 32960 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50213@lists.php.net to get a copy of this message | ||
Mentioned above is some advice about using str_replace to parse text to go inside javascript
document.write()s, however, both seem to be wrong. 1) You don't need to escape ' inside a
" in php. 2) You should do your slash escaping first so as not to double-escape slashes.
Here's my code:
$string=str_replace("\\", "\\\\", $string);
$string=str_replace("'", "\'", $string);
$string=str_replace("\"", "\\\"", $string);
Hope that saves someone some confusion.
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32960
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32960&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32960&report=yes