note 85265 deleted from function.mysql-real-escape-string by mgf

From: Date: Wed, 27 Aug 2008 12:11:08 +0000
Subject: note 85265 deleted from function.mysql-real-escape-string by mgf
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143868@lists.php.net to get a copy of this message
Note Submitter: tomas dot ehrlich at gmail dot com ---- Reply to: zareef at zareef dot net If you simply print escaped string, new lines and carriage returns will be changed to literal \n and \r, as you say. When you put this string to the database and take it back, everythink seems to be ok: <?php // Example: $msg = mysql_real_escape_string ("hi,\nI'm the new line"); // echo $msg shows: hi,\nI'm the new line $sql = sprintf ('INSERT INTO test (msg) VALUES ("%s")', $msg); mysql_query ($sql); $sql = 'SELECT msg FROM test'; $res = mysql_query ($sql); $item = mysql_fetch_assoc ($res); echo $item['msg']; ?> Now we get: hi, I'm the new line

« previous php.notes (#143868) next »