note 108777 modified in function.str-replace by danbrown

From: Date: Thu, 24 May 2012 17:29:15 +0000
Subject: note 108777 modified in function.str-replace by danbrown
References: 1  Groups: php.notes php.notes 
Request: Send a blank email to php-notes+get-188200@lists.php.net to get a copy of this message
I noticed that if you use mysql_real_escape_string() before performing str_replace, it won&#39;t work. This may be dependent on the string being replaced. Specifically, the following, won&#39;t work:&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$formattedPost = mysql_real_escape_string($formattedPost);&#13;&#10;$formattedPost = str_replace(&#34;\\r\\n&#34;, &#34;&#60;br&#62;&#34;, $comment);&#13;&#10;?&#62;&#13;&#10;&#13;&#10;Do this instead:&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$formattedPost = str_replace(&#34;\\r\\n&#34;, &#34;&#60;br&#62;&#34;, $comment);&#13;&#10;$formattedPost = mysql_real_escape_string($formattedPost);&#13;&#10;?&#62; --was-- I noticed that if you use mysql_real_escape_string() before performing str_replace, it won't work. This may be dependent on the string being replaced. Specifically, the following, won't work: $formattedPost = mysql_real_escape_string($formattedPost); $formattedPost = str_replace("\r\n", "<br>", $comment); Do this instead: $formattedPost = str_replace("\r\n", "<br>", $comment); $formattedPost = mysql_real_escape_string($formattedPost); http://php.net/manual/en/function.str-replace.php

« previous php.notes (#188200) next »