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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 08:01:29 2025 UTC