php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32068 Parse not executed while using the perl comment(#) with patterns
Submitted: 2005-02-22 22:56 UTC Modified: 2005-02-22 23:12 UTC
From: simon at ruderich dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.10 OS: Mac OS X 10.3.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: simon at ruderich dot com
New email:
PHP Version: OS:

 

 [2005-02-22 22:56 UTC] 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";  ?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-22 23:12 UTC] derick@php.net
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)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 19:01:32 2024 UTC