#21816 [NEW]: preg_replace has problem with arrays
| From: | grischa dot toedt at web dot de | Date: | Wed, 22 Jan 2003 13:43:39 +0000 |
| Subject: | #21816 [NEW]: preg_replace has problem with arrays | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-30917@lists.php.net to get a copy of this message | ||
From: grischa.toedt@web.de
Operating system: Windows XP
PHP version: 4.3.0
PHP Bug Type: *Regular Expressions
Bug description: preg_replace has problem with arrays
<?php
// Hi, while using the following code i experienced
// an interesting behaviour of preg_replace():
$string = "Say a [word0] about [word1] and [word2]";
$search[0] ="[word0]";
$search[1]= "[word1]";
$search[2]= "[word2]";
$replace[0]="betterWord0";
$replace[2]="betterWord2";
$replace[1]="betterWord1";
$string = preg_replace($search,$replace,$string);
echo "Result is:<BR>" . $string;
echo "<BR><BR>Result should be:<BR> Say a [betterWord0] about
[betterWord1] and [betterWord2]";
// result should be:
//Say a [betterWord0] about [betterWord1] and [betterWord2]
//
// but produces:
//Say a [betterWord0] about [betterWord2] and [betterWord1]
//
// Seems like the order in which i build my array
// is the order for replacing...and not the index
// of $array[$index]
//
//
// Has someone an idea, about what's happening here?
//
// just a guy addicted to php ;-)
?>
--
Edit bug report at http://bugs.php.net/?id=21816&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=21816&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=21816&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=21816&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=21816&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=21816&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=21816&r=support
Expected behavior: http://bugs.php.net/fix.php?id=21816&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=21816&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=21816&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=21816&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21816&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=21816&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=21816&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=21816&r=gnused