Re: preg_replace problem

[email protected] (Al)
Newsgroups php.general
Message-ID <[email protected]>

Shawn McKenzie wrote:
> Al wrote:
>> This preg_replace() should simply replace all "&" with "&amp;" unless
>> the value is already "&amp;"
>>
>> 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 tried IE8 thinking it could be a weird browser bug. Same error.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.