#32068 [Opn->Bgs]: Parse not executed while using the perl comment(#) with patterns
| From: | derick@php.net | Date: | Tue, 22 Feb 2005 22:12:57 +0000 |
| Subject: | #32068 [Opn->Bgs]: Parse not executed while using the perl comment(#) with patterns | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-74437@lists.php.net to get a copy of this message | ||
ID: 32068
Updated by: derick@php.net
Reported By: simon at ruderich dot com
-Status: Open
+Status: Bogus
Bug Type: Output Control
Operating System: Mac OS X 10.3.8
PHP Version: 4.3.10
New Comment:
This line:
#$pattern = '#\( (( (?>[^()]+) | (?R) )*) \)#isUx';
has a ?> in it, which marks the end of a script block.
No bug here (this is also documented in the manual)
Previous Comments:
------------------------------------------------------------------------
[2005-02-22 22:56:29] simon at ruderich dot com
Description:
------------
I wanted to replace a string using the 'preg_replace'-
function. I tried more patterns, so I commented out the
old patterns. But then it showed me not the replace
string. This must be a problem with the perl comment (#)
because if I use /* */ to comment out the old pattern
the script works.
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
$string = " <a> asdf </a> <a> <a> test </a>
<a> test
</a> <a> test </a> </a> <a>asdf</a>
<a>asdf</a> ";
#$pattern = '#<a>( ( ([^<>])|(?R) )*? )</a>#isx';
#$pattern = '#<a>( ( (?R)|() )*? )</a>#isx';
#$pattern = '#\( (( (?>[^()]+) | (?R) )*) \)#isUx';
$pattern = '#<a>( (.)*? )</a>#isxU';
$replace = '[a]$1[/a]';
echo '<pre>'."\n";
echo htmlspecialchars($string);
echo "\n\n";
echo htmlspecialchars(preg_replace($pattern, $replace, $string));
echo '</pre>'."\n";
?>
Expected result:
----------------
<a> asdf </a> <a> <a> test </a> <a> test
</a> <a> test </a> </a> <a>asdf</a> <a>asdf</
a>
[a] asdf </a> <a> <a> test </a> <a> test
</a> <a> test </a> </a> <a>asdf</a> <a>asdf[/
a]
Actual result:
--------------
[^()]+) | (?R) )*) \)#isUx'; $pattern = '#( (.)*?
)#isxU'; $replace = '[a]$1[/a]'; echo '
'."\n";
echo htmlspecialchars($string);
echo "\n\n";
echo htmlspecialchars(preg_replace($pattern, $replace,
$string));
echo '
'."\n"; ?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32068&edit=1