ID: 15166 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: WINDOWS 2000 PHP Version: 4.1.1 New Comment:
This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2002-01-24 11:32:30] [EMAIL PROTECTED] '{$1}' or "{\$1}" ------------------------------------------------------------------------ [2002-01-24 11:27:17] [EMAIL PROTECTED] I tried the syntax {$1} with PHP 4.1.1 as below: 1/ $test=preg_replace("/(<\!DOCTYPE\s+map\s+SYSTEM\s+\"http:\/\/)[^\/]+/i","{$1}$servname:$servport",$test); It gives me the following error: Parse error: parse error, expecting `T_VARIABLE' or `'$'' in C:\inetpub\wwwroot\bug2.php on line 33 2/ Escaping the first brace: $test=preg_replace("/(<\!DOCTYPE\s+map\s+SYSTEM\s+\"http:\/\/)[^\/]+/i","\{$1}$servname:$servport",$test); The result is the following one: test2 RESULT :{<!DOCTYPE map SYSTEM "http://}10.0.9.91:81/Gui/dtd/deployment/dbmap.dtd"> It is escaping properly the 1 contained in $servername but keep the braces. 3/ The only way I found to escape $servername is by using the value 99 as follow: $test=preg_replace("/(<\!DOCTYPE\s+map\s+SYSTEM\s+\"http:\/\/)[^\/]+/i","\\1\\99$servname:$servport",$test); 991 is not taken because of the limitation to 99 different strings. I just need to make sure I am not using 99 different parentheses which is pretty huge. ------------------------------------------------------------------------ [2002-01-22 17:26:53] [EMAIL PROTECTED] You'd either need to escape the number after your reference, ie: \\1\1 or if you're using PHP 4.0.4 or later, you can use {$1} in the replacement portion of preg_replace (see documentation). ------------------------------------------------------------------------ [2002-01-22 15:00:59] [EMAIL PROTECTED] What do you think about the following suggestions: A/ Counting how many string are enclosed by parentheses. preg_replace("/(......)test(....)/","\\110.0.0.173",$test); => expecting 2 strings enclosed Then parse the value following \\ and keep only the one lower than the max expected. Expecting 2: \\1 OK \\11 TOO high, keep \\1 I do not know what the impact might be in term of performance. => Implementing a way to escape might be faster. B/ Using a different notation to escape the string following \\1 (brace for example) preg_replace("/(......)test(....)/","\\{1}10.0.0.173",$test); Thanks for your prompt answer, that was quick :-) ------------------------------------------------------------------------ [2002-01-22 14:44:12] [EMAIL PROTECTED] \\11 matches the 11th string enclosed by parenthesis. Can't find anything about escaping it. Reclassified as a documentation problem. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/15166 -- Edit this bug report at http://bugs.php.net/?id=15166&edit=1 -- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php