Re: preg_replace problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Shawn McKenzie wrote:
Al wrote:
This preg_replace() should simply replace all "&" with "&" unless
the value is already "&"

But; if $value is simple a quote character ["] I get "&quote". e.g.,
"test" => &quote;test&quote;

Search string and replace works as it should in Regex_Coach.

echo $value.'<br />';
$value=preg_replace("%&(?!amp;)%i", "&amp;", $value);
echo $value;

I tried using \x26 for the "&" in the search string; didn't help.

This seems too obvious to be a bug. Using php5.2.9

Al.......

Your code works for me, unless I'm misunderstanding the problem.  With
the following:

$value = "&quote;test&quote;";

I get:

&quote;test&quote;<br />
&amp;quote;test&amp;quote;


I may not have been very clear. Feed it just "test" with the quotes. You should get back, "test" the same as you gave it. Instead, I get back &quote;test&quote;

Like wise, if I give it just a single quote ["] I get back [&quote;]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux