#39695 [Fbk->Opn]: preg_replace returns NULL if no match, instead of unmodified subject
| From: | ivo_gelov at abv dot bg | Date: | Thu, 30 Nov 2006 18:05:45 +0000 |
| Subject: | #39695 [Fbk->Opn]: preg_replace returns NULL if no match, instead of unmodified subject | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-105705@lists.php.net to get a copy of this message | ||
ID: 39695
User updated by: ivo_gelov at abv dot bg
Reported By: ivo_gelov at abv dot bg
-Status: Feedback
+Status: Open
Bug Type: PCRE related
Operating System: Linux Fedora Core 4
PHP Version: 5.2.0
New Comment:
I checked "$2$1" instead of "\$2\$1" and it worked.
So this is my fault since I was looking an example in an old manual,
not the current one.
Sorry for disturbing.
But there is another issue - when I used preg_replace in PHP 5.1.4 with
a relatively long string as a subject, it worked without problems. But
after upgrade to 5.2.0, it now gives me an error
PREG_BACKTRACK_LIMIT_ERROR with default value for
"pcre.backtrack_limit" (not listed in PHP.INI at all). What can I do ?
Should I revert back to 5.1.4 ?
Or just compile 5.2.0 with the 6.6 version of PCRE library ?
Previous Comments:
------------------------------------------------------------------------
[2006-11-30 17:36:52] tony2001@php.net
Not reproducible.
Btw, this code - $rep = '\$2\$1'; apparently won't work.
------------------------------------------------------------------------
[2006-11-30 16:55:02] ivo_gelov at abv dot bg
Description:
------------
There are 2 strange effects/bugs, may be one depends on the other, I do
not know.
1. PREG_REPLACE does not recognize $n as a back reference in its second
argument. It will recognize only \\n references.
2. PREG_REPLACE returns NULL if no match is found, instead of returning
unmodified subject
This symptom is present only in 5.2.0 - there are no problems with
5.1.0
Reproduce code:
---------------
$pat = '/^([a-zA-Z])(\d*)$/';
$rep = '\$2\$1';
$b = preg_replace($pat,$rep,'D764209812');
Expected result:
----------------
$b should be '764209812D'
Actual result:
--------------
$b is NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39695&edit=1