note 32071 added to function.htmlentities
| From: | professeur_sciences at hotmail dot com | Date: | Thu, 15 May 2003 12:07:50 +0000 |
| Subject: | note 32071 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48019@lists.php.net to get a copy of this message | ||
A solution for a problem with ' (simple quote)
If you need to display one string (for example "pooch'y" ) which contains the
character ' :
·1) with a the echo function
AND
·2) also by a javascript function (such as alert() or Document.Write() etc ...
You have a problem because the javascript function will need \' to display correctly, and the
echo function needs only ' to display correctly (i.e. if you have \' in the string, the
echo function will display pooch\'y instead of pooch'y)
So my solution is :
Before inserting the string in your database, do htmlentities($string);
Then insert it, it will be in your database pooch'y
This way the echo function will display pooch'y without problem.
Now to display correctly the same string with a javascript function just do $string =
str_replace("'", "\'", $string);
and the display will work without error.
Hope that'll help :>
--
http://www.php.net/manual/en/function.htmlentities.php
http://master.php.net/manage/user-notes.php?action=edit+32071
http://master.php.net/manage/user-notes.php?action=delete+32071
http://master.php.net/manage/user-notes.php?action=reject+32071