From: [EMAIL PROTECTED] Operating system: WINDOWS 2000 PHP version: 4.1.1 PHP Bug Type: *Regular Expressions Bug description: preg_replace issue when \\1 is followed by 1
1/DETAIL: When I am using preg_replace with \\1 to keep the first iteration retrieved, if \\1 is followed by a string starting by 1, this is removing the 1 of the string and losing the content of \\1. Here is a script to show 4 test cases. The test2 and test4 failed because of this issue. The test3 is the solution i found to avoid this issue by inserting any character different from 1 just after \\1. Thanks in advance for your help. Pierre <? $value='<!DOCTYPE map SYSTEM "http://localhost/Gui/dtd/deployment/dbmap.dtd">'; $servname='10.0.9.91'; $servport='81'; // TITLE print "<HR><CENTER>\n"; print("<b>BUG with <font color='red'>preg_replace</font> and <font color='red'>\\\\1</font> followed by a variable starting by 1</b><BR><BR>\n"); print("<B> WINDOWS 2000 platform, PHP version 4.1.1<BR></b>\n"); print("<xmp>ORIGINAL VALUE:".$value."</xmp>\n"); print "<HR></CENTER>\n"; // TEST 1 with servname='localhost'; $testservname='localhost'; $test=$value; $expected='<!DOCTYPE map SYSTEM "http://'.$testservname.':'.$servport.'/Gui/dtd/deployment/dbmap.dtd">'; $test=preg_replace("/(<\!DOCTYPE\s+map\s+SYSTEM\s+\"http:\/\/)[^\/]+/i","\\1$testservname:$servport",$test); $status ='OK'; if ($test != $expected) $status='WRONG'; print "<xmp>\n"; print_r("test1 SERVER NAME:$testservname SERVER PORT:$servport\n"); print_r("test1 OPERATION: \$test=preg_replace(\"/(<\!DOCTYPE\s+map\s+SYSTEM\s+\"http:\/\/)[^\/]+/i\",\"\\\\1\$testservname:\$servport\",\$test);"."\n"); print_r("test1 RESULT :".$test."\n"); print_r("test1 EXPECTED:".$expected."\n"); print "</xmp><BR>\n"; print("test1 STATUS :<font color='red'>".$status."</font><BR><HR>\n"); //TEST 2 with servname = '10.0.9.91'; $test=$value; $testservname=$servname; $expected='<!DOCTYPE map SYSTEM "http://'.$testservname.':'.$servport.'/Gui/dtd/deployment/dbmap.dtd">'; $test=preg_replace("/(<\!DOCTYPE\s+map\s+SYSTEM\s+\"http:\/\/)[^\/]+/i","\\1$servname:$servport",$test); $status ='OK'; if ($test != $expected) $status='WRONG'; print "<xmp>\n"; print_r("test2 SERVER NAME:$testservname SERVER PORT:$servport\n"); print_r("test2 OPERATION: \$test=preg_replace(\"/(<\!DOCTYPE\s+map\s+SYSTEM\s+\"http:\/\/)[^\/]+/i\",\"\\\\1\$testservname:\$servport\",\$test);"."\n"); print_r("test2 RESULT :".$test."\n"); print_r("test2 EXPECTED:".$expected."\n"); print"</xmp><BR>\n"; print("test2 STATUS :<font color='red'>".$status."</font><BR><HR>\n"); // TEST3 $test=$value; $testservname=$servname; $expected='<!DOCTYPE map SYSTEM "http://'.$testservname.':'.$servport.'/Gui/dtd/deployment/dbmap.dtd">'; $test=preg_replace("/(<\!DOCTYPE\s+map\s+SYSTEM\s+\")http:\/\/[^\/]+/i","\\1http://$servname:$servport",$test); $status ='OK'; if ($test != $expected) $status='WRONG'; print "<xmp>\n"; print_r("test3 SERVER NAME:$testservname SERVER PORT:$servport\n"); print_r("test3 OPERATION: \$test=preg_replace(\"/(<\!DOCTYPE\s+map\s+SYSTEM\s+\")http:\/\/[^\/]+/i\",\"\\\\1http://\$testservname:\$servport\",\$test);"."\n"); print_r("test3 RESULT :".$test."\n"); print_r("test3 EXPECTED:".$expected."\n"); print "</xmp><BR>\n"; print("test3 STATUS :<font color='red'>".$status."</font><BR><HR>\n"); // TEST4 $test="this is a test with any string"; $testservname='1234567890'; $expected='this is a '.$testservname.':'.$servport.' with any string'; $test=preg_replace("/(this is a )test/i","\\1$testservname:$servport",$test); $status ='OK'; if ($test != $expected) $status='WRONG'; print "<xmp>\n"; print_r("test4 SERVER NAME:$testservname SERVER PORT:$servport\n"); print_r("test4 OPERATION: \$test=preg_replace(\"/(this is a)test/i\",\"\\\\1\$testservname:\$servport\",\$test);"."\n"); print_r("test4 RESULT :".$test."\n"); print_r("test4 EXPECTED:".$expected."\n"); print "</xmp><BR>\n"; print("test4 STATUS :<font color='red'>".$status."</font><BR><HR>\n"); // General comments print "<BR><b>COMMENTS</b>: test2 and test4 failed<BR>\n"; print "The issue happens only if \$testservname start by 1. For example with test1 the substitution works since the value of \$testservname does not start by 1\n"; print "<HR>\n"; ?> -- Edit bug report at: http://bugs.php.net/?id=15166&edit=1 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]