php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33437 comments throwing preg_replace script
Submitted: 2005-06-22 17:47 UTC Modified: 2005-06-22 18:04 UTC
From: php at karsites dot net Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.10 OS: SuSE Linux 9.2 pro
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: php at karsites dot net
New email:
PHP Version: OS:

 

 [2005-06-22 17:47 UTC] php at karsites dot net
Description:
------------
I'm actually on php4-4.3.8-8.7 - stuck with that at the 
moment,as that ships with my Linux distro - SuSE 9.2 pro  
  
I did search the database for 'coments' but found nothing 
there regarding this possible bug. 
 
The code below trashes the script with the   
commented line in the script  
  
// original regex $regex = "!(</?)(\w+)([^>]*?>)!e";  
  
Surely, everything to the right of // should be ignored  
as a comment?  
  
With the comment in place, the script produces the  
following trashed output:  
  
)!e"; $regex = "!(]*?>)!e"; $replacement =  
"'\\1'.strtolower('\\2').'\\3'"; $subject = " A rose"; echo  
"Before replacement \$subject is: $subject   
"; $new_sub = preg_replace($regex, $replacement, $subject);  
echo "After replacement \$subject is: $new_sub   
"; ?>  
  
Is this a bug, because it is not expected behaviour.  
  
If I remove the offending comment, the script produces the  
correct output.  
  
Regards - Keith Roberts  
  
  

Reproduce code:
---------------
<?php

// original regex $regex = "!(</?)(\w+)([^>]*?>)!e";

$regex = "!(</?)(\w+)([^>]*?>)!e";

$replacement = "'\\1'.strtolower('\\2').'\\3'";

$subject = "<BIGTEXT> A <BIGGEST>rose</BIGGEST> <PARA></BIGTEXT>";

echo "Before replacement \$subject is: $subject <br />";

$new_sub = preg_replace($regex, $replacement, $subject);
echo "After replacement \$subject is: $new_sub <br />";

?>



Expected result:
----------------
Before replacement $subject is: A rose 
After replacement $subject is: A rose  
 
(the browser ignores the dummy tags, but the correct result 
can be seen with 'view source code' - ie lowercased tags) 
 
 

Actual result:
--------------
 
)!e"; $regex = "!(]*?>)!e"; $replacement = 
"'\\1'.strtolower('\\2').'\\3'"; $subject = " A rose"; echo 
"Before replacement \$subject is: $subject  
"; $new_sub = preg_replace($regex, $replacement, $subject); 
echo "After replacement \$subject is: $new_sub  
"; ?> 
 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-22 18:01 UTC] php at karsites dot net
Woops!  
 
I've just noticed the ?> in the regular expression. 
 
Obviously, this has been recognised as the 'back to html 
mode' php tag! 
 
Keith
 [2005-06-22 18:04 UTC] tony2001@php.net
So, no bug here -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC