Posted by lawrence k on 12/06/05 08:46
dennis.alund@gmail.com wrote:
> This isn't really a solution to your problem... just a hint of what's
> wrong; a quote is also a character... i.e. in the expression (.*) will
> also match a quote.
> What you want to look into is negative lookarounds; (?<!x)y matches an
> 'y' not preceeded by a 'x' and x(?!y) matches a 'x' not followed by an
> 'y'.
> But if you're not a regexp-ninja I'd recommend you to find an easier
> solution... negative lookarounds aint trivial.
Thanks for the reply. I just created this file and I uploaded it to my
server for testing:
<?php
echo "hey";
flush();
function command($string=false) {
echo "hey";
$pattern = '/(.*)<a (.*)"[^"]+>/i';
$replacement = '$1<a $2"$3">';
// $newString = preg_replace($pattern, $replacement, $string);
return $newString;
}
$string = "<p><a href=\"myfile>myfile</a> ";
echo $string;
flush();
$string = command($string);
echo $string;
?>
When I don't comment out the preg_replace line then I get one "hey"
echoed to the screen and then the script apparently dies without error.
Navigation:
[Reply to this message]
|