From:             simon at ruderich dot com
Operating system: Mac OS X 10.3.8
PHP version:      4.3.10
PHP Bug Type:     Output Control
Bug description:  Parse not executed while using the perl comment(#) with 
patterns

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 bug report at http://bugs.php.net/?id=32068&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32068&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32068&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32068&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32068&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32068&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32068&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32068&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32068&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32068&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32068&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32068&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32068&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32068&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32068&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32068&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32068&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32068&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32068&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32068&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32068&r=mysqlcfg

Reply via email to