ID: 32404
Updated by: [EMAIL PROTECTED]
Reported By: thomas-meyer at uni dot de
-Status: Open
+Status: Bogus
Bug Type: PCRE related
Operating System: Windows XP
PHP Version: 4.3.10
New Comment:
RTFM:
"..backreference is immediately followed by another number you cannot
use the familiar \\1 notation..
..the solution is to use \${1}1. This creates an isolated $1
backreference, leaving the 1 as a literal."
This works as you expect:
echo preg_replace("/(<[^>]*)test([^>]*>)/i", "\${1}{$a}\${2}",
$temp);
Previous Comments:
------------------------------------------------------------------------
[2005-03-21 23:03:08] thomas-meyer at uni dot de
Description:
------------
There is a problem with PCRE in both PHP-versions (4.3.10 and 5.0.3)
When using preg_replace with:
$b = preg_replace("/(some)thing/", "\\1$replace", $a);
This works fine, as long as $replace does start with any character that
is NOT a number.
BUT: if $replace starts with a number (like "1abc") FIRST this string:
"\\11abc" will be created.
THEN it will try to replace \\11 by the 11th remembered position
instead of replacing \\1 with the 1st one.
This bug could lead to strange/unexpected results and should be fixed
soon.
Reproduce code:
---------------
<?php
$temp = '<input value="test">';
$a = 123;
echo "<P>Perl</P>\n";
$temp1 = preg_replace("/(<[^>]*)test([^>]*>)/Usi", "\\1".$a."\\2",
$temp);
echo $temp1;
echo "<P>POSIX</P>\n";
$temp1 = eregi_replace("(<[^>]*)test([^>]*>)", "\\1".$a."\\2",
$temp);
echo $temp1;
?>
Expected result:
----------------
<P>Perl</P>
<input value="123">
<P>POSIX</P>
<input value="123">
Actual result:
--------------
<P>Perl</P>
23">
<P>POSIX</P>
<input value="123">
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32404&edit=1