note 33431 deleted from function.mysql-escape-string by alindeman
| From: | alindeman@php.net | Date: | Wed, 25 Jun 2003 19:11:36 +0000 |
| Subject: | note 33431 deleted from function.mysql-escape-string by alindeman | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-51006@lists.php.net to get a copy of this message | ||
Note Submitter: Andy Chase <monkey@greyledge.net>
----
Here's a gotcha - as noted in a previous comment, mysql_escape_string() will add escape \r and
\n characters, but stripslashes() won't convert them back into actual CR/newline characters; so
if you have some text with linebreaks like:
Line
Break
mysql_escape_string will convert it to
Line\r\n\r\nBreak
(or "Line\n\nBreak" or "Line\r\rBreak" depending on your platform)
Unfortunately, stripslashes() on this string returns:
LinernrnBreak
(or LinennBreak or LinerrBreak). Perhaps a future version of PHP will implement a native
mysql_unescape_string() function? In the meantime, something like this will work:
function mysql_unescape_string($string){
return stripslashes(str_replace(array('\r', '\n'), array("\r",
"\n"), $string));
}