Re: [PHP] Re: preg_replace problem

[email protected] (Mark Kelly)
Newsgroups php.general
Organization Obscure Technical Services
Message-ID <[email protected]>
Hi.

On Saturday 13 June 2009, Al wrote:
> 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 Shawn, I have tried your code in isolation and only get the expected 
results. I looped it over a few test values:

<?php
$valueList = array('"','"test"','"test&test"','"test&amp;test"');
echo "<pre>\n\n";
foreach ($valueList as $value) {
	echo "Before: $value\n";
	$value=preg_replace("%&(?!amp;)%i", "&amp;", $value);
	echo "After: $value\n\n";
}
echo '</pre>';
?>

outputs (ignoring <pre> as that was just to remove the <br /> for easy 
reading):

Before: "
After: "

Before: "test"
After: "test"

Before: "test&test"
After: "test&amp;test"

Before: "test&amp;test"
After: "test&amp;test"

The only conclusion is that something else in your code is converting the 
quotes. Have a look around.

HTH

Mark
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.