note 32071 deleted from function.htmlentities by alindeman

From: Date: Thu, 15 May 2003 20:45:30 +0000
Subject: note 32071 deleted from function.htmlentities by alindeman
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-48045@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 :>

« previous php.notes (#48045) next »