Re: [PHP4BETA] PCRE problems
| From: | Andrei Zmievski | Date: | Fri, 05 May 2000 14:01:34 +0000 |
| Subject: | Re: [PHP4BETA] PCRE problems | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-14527@lists.php.net to get a copy of this message | ||
On Thu, 04 May 2000, Daniel Landau wrote:
> Andrei,
> Well, I've managed to track down the source of my grief... Maybe I
> shouldn't be able to do what I'm doing.
> Here's a bit of code that breaks strangely:
>
> <?
> $html = '<? echo \'<IMG SRC="\'foo">\'; ?>';
> echo "Pre: ##$html##";
>
> $pattern = '/(<IMG.+SRC=")([^"]+)"/eisU';
> $html = preg_replace($pattern, "'\\1' . foo('\\2',
> '$this->url', '$server')
> . '\"'", $html);
>
> function foo ($text) {
> echo 'ALTERED' . $text . 'ALTERED';
> }
> ?>
>
> Some permutations of this don't seg-fault but do produce messages of this
> sort:
> Parse error: parse error in Unknown on line 0
I didn't get Zend errors here, using the latest PHP.
You have a couple of problems in your code. Firstly, you should use
'return' instead of 'echo' in foo(). Secondly, the reason you get that
parse error is that the \\2 subpattern already contains both ' and "
which fails in internal evaluation when combined with your function
call. Internally, the function call looks like:
foo(''foo', '$this->url', '$server')
So, either you have to use \\\' in $html or use another regular
expression to escape them one more time before you do your /e magic.
-Andrei
* Entropy isn't what it used to be. *