note 103592 added to function.preg-replace

From: Date: Thu, 21 Apr 2011 16:07:56 +0000
Subject: note 103592 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-179053@lists.php.net to get a copy of this message
Note that strange behavior of preg_replace when using backslashes in your $replacement, to avoid SQL-Injection: <?php // string '\\\"' (length=4) - correct result str_replace("foo", mysql_real_escape_string('\"'), 'foo'); // string '\\"' (length=3) - one slash missing preg_replace("~foo~", mysql_real_escape_string('\"'), 'foo'); // string '\\\\"' (length=5) - escaped backslashes, now have too much preg_replace("~foo~", addslashes(mysql_real_escape_string('\"')), 'foo'); // string '\.\.\"' (length=6) - '\\.\\.\"' has the same backslash count as mysql_real_escape_string('\"') but after replacement, they are different preg_replace("~foo~", '\\.\\.\"', 'foo'); ?> ---- Server IP: 217.160.235.204 Probable Submitter: 85.183.47.159 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/103592 Del: integrated -- https://master.php.net/note/delete/103592/integrated Del: useless -- https://master.php.net/note/delete/103592/useless Del: bad code -- https://master.php.net/note/delete/103592/bad+code Del: spam -- https://master.php.net/note/delete/103592/spam Del: non-english -- https://master.php.net/note/delete/103592/non-english Del: in docs -- https://master.php.net/note/delete/103592/in+docs Del: other reasons-- https://master.php.net/note/delete/103592 Reject -- https://master.php.net/note/reject/103592 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179053) next »