Bug #16786: ereg_replace substitution behaving badly
| From: | tom at scl dot co dot uk | Date: | Wed, 24 Apr 2002 09:12:16 +0000 |
| Subject: | Bug #16786: ereg_replace substitution behaving badly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-5793@lists.php.net to get a copy of this message | ||
From: tom@scl.co.uk
Operating system: Linux 2.2.19
PHP version: 4.2.0
PHP Bug Type: Regexps related
Bug description: ereg_replace substitution behaving badly
Hi,
I have just downloaded PHP4.0.2 and several pieces of code broke because
ereg_replace() seemed to be working incorrectly:
if for example I did the following:
$str = "word1-word2";
$str = ereg_replace("^([^-]*)-(.*)", '\1+\2', $str);
it works as expected, ($str == "word1+word2")
The problem arises if one of the parenthasized subexpression is empty the
\x (where x is the number of the subexpression) in the replace string does
not get replaced at all, instead of with the empty string eg:
$str = "-word2";
$str = ereg_replace("^([^-]*)-(.*)", '\1+\2', $str);
for this example I'd expect the result to be ($str == "+word2") but
instead you get ($str == "\1+word2") because \1 is empty.
I don't believe that this is meant to happen but if it is how are we meant
to deal with such a case?
--
Edit bug report at http://bugs.php.net/?id=16786&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=16786&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=16786&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=16786&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=16786&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=16786&r=support
Expected behavior: http://bugs.php.net/fix.php?id=16786&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=16786&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=16786&r=submittedtwice