ID: 23946 Updated by: [EMAIL PROTECTED] Reported By: stuge-phpbugs at cdy dot org -Status: Open +Status: Verified Bug Type: *Regular Expressions Operating System: Linux -PHP Version: 4.3.1 +PHP Version: 4.3.2 New Comment:
Verified with 4.3.2 (and 4.3.1 and 4.2.3). Similar to #23903, but here I see why you want to use [ep]reg_replace. Previous Comments: ------------------------------------------------------------------------ [2003-06-01 22:38:09] stuge-phpbugs at cdy dot org Verified with 4.3.0 and 4.3.2rc2 but haven't tried 4.3.2. NEWS for 4.3.2 do not mention any *reg_replace changes. Reproducible with eregi_replace(). <?php $f="xyz"; $g=ereg_replace("z?$","a",$f); $h=preg_replace("/z?$/","a",$f); print $f; /* xyz */ print " ".$g; /* xyaa, I want xya */ print " ".$h; /* xyaa, I want xya */ ?> At least in CVS php4/ext/standard/reg.c I believe the problem is that regexec() on line 306 will be called a second time after the first iteration has already matched to the end of the string. Matching from the end of the string should only be allowed on the very first iteration. If this analysis is correct, the following patch might work, but I haven't tried it. --- reg.c.org 2003-06-02 05:23:51.000000000 +0200 +++ reg.c 2003-06-02 05:26:06.000000000 +0200 @@ -302,7 +302,7 @@ err = pos = 0; buf[0] = '\0'; - while (!err) { + do { err = regexec(&re, &string[pos], re.re_nsub+1, subs, (pos ? REG_NOTBOL : 0)); if (err && err != REG_NOMATCH) { @@ -396,7 +396,7 @@ /* stick that last bit of string on our output */ strcat(buf, &string[pos]); } - } + } while(!err && string[pos]); /* don't want to leak memory .. */ efree(subs); ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23946&edit=1