note 33431 added to function.mysql-escape-string

From: Date: Wed, 25 Jun 2003 19:07:28 +0000
Subject: note 33431 added to function.mysql-escape-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-51005@lists.php.net to get a copy of this message
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)); } ---- Manual Page -- http://www.php.net/manual/en/function.mysql-escape-string.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33431 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33431&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33431&report=yes

« previous php.notes (#51005) next »