Bug #10668 Updated: preg_replace backquote failure
| From: | smoonen at andstuff dot org | Date: | Fri, 03 Aug 2001 16:00:07 +0000 |
| Subject: | Bug #10668 Updated: preg_replace backquote failure | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-61980@lists.php.net to get a copy of this message | ||
ID: 10668
User updated by: smoonen@andstuff.org
Reported By: smoonen@andstuff.org
Old Status: Analyzed
Status: Closed
Bug Type: PCRE related
Operating System: Linux
PHP Version: 4.0.5
New Comment:
Appears to have been a passing bug in a particular compile. Cannot repeat. Closing.
Previous Comments:
------------------------------------------------------------------------
[2001-05-04 15:32:15] smoonen@andstuff.org
H'm... I'm confused. :-) To complicate things further, the e-mails display half as many
backslashes as the web page. :-) Since I'm not sure what you mean, I'll exhaustively list
the behaviors:
The following:
$str = "abc'\\\\''def";
function f($s) { var_dump($s); return "x"; }
print preg_replace("/c(.*)d/e", "f('\\1')", $str);
gives the error messages I posted earlier. (That's two backslashes before the 1.)
The following:
$str = "abc'\\\\''def";
function f($s) { var_dump($s); return "x"; }
print preg_replace("/c(.*)d/e", "f('\\\\1')", $str);
gives the result:
string(2) "\1" abxef
which isn't what I want. (That's four backslashes before the 1.)
Prefixing the "1" with one or three backslashes in each case emits an ASCII
x'01'.
None of which are what I want to occur...
------------------------------------------------------------------------
[2001-05-04 15:17:51] andrei@php.net
Oops, \\1 instead of \1.
------------------------------------------------------------------------
[2001-05-04 15:17:15] andrei@php.net
Ok, I made a little mistake, use "f('\\\\1')" rather than
"f('\1')".
------------------------------------------------------------------------
[2001-05-04 13:59:27] smoonen@andstuff.org
Oddly, I get the following error:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
/home/groups/t/ta/tavi/htdocs/playground/test.php(4) : regexp code on line 1
Parse error: parse error in /home/groups/t/ta/tavi/htdocs/playground/test.php(4) : regexp code on
line 1
Fatal error: Failed evaluating code: f('\'\\\\'\'') in
/home/groups/t/ta/tavi/htdocs/playground/test.php on line 4
PHP compile options may be seen at:
http://tavi.sourceforge.net/playground/phpinfo.php
------------------------------------------------------------------------
[2001-05-04 12:58:12] andrei@php.net
Can you explain why you think it fails? The following sample (slightly modified from yours to dump
the $s parameter to function):
$str = "abc'\\\\''def";
function f($s) { var_dump($s); return "x"; }
print preg_replace("/c(.*)d/e", "f('\\1')", $str);
outputs:
string(5) "'\\''"
abxef
As it should.
------------------------------------------------------------------------
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/?id=10668
Edit this bug report at http://bugs.php.net/?id=10668&edit=1