note 52135 deleted from function.preg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 18 Jun 2006 13:26:25 +0000 |
| Subject: | note 52135 deleted from function.preg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114312@lists.php.net to get a copy of this message | ||
Note Submitter: bens at effortlessis dot com
----
It's important to note how preg_match actually works when processing arrays - it's the
same as running preg_match repeatedly in serial.
Here's a demonstration:
<?
$a="a b c";
echo "Sample 1 ";
echo $b=str_replace("b", "_", $a);
echo "\n";
echo "Sample 2 ";
echo str_replace("_", "BAD", $b);
echo "\n";
$find=array('/b/', "/_/");
$replace=array('_', 'BAD');
echo "Sample 3 ";
echo preg_replace($find, $replace, $a);
echo "\n";
?>
This prints out
Sample 1 a _ c
Sample 2 a BAD c
Sample 3 a BAD c
Since I'd expected preg_replace to operate in one pass, I'd expected the output to be:
Sample 1 a _ c
Sample 2 a BAD c
Sample 3 a b c