note 123144 deleted from function.preg-replace by crell
| From: | crell@php.net | Date: | Fri, 01 Jul 2022 19:43:26 +0000 |
| Subject: | note 123144 deleted from function.preg-replace by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218848@lists.php.net to get a copy of this message | ||
Note Submitter: willbrownsberger at gmail dot com
----
Worth knowing: When arrays of patterns and replacements are provided, they are executed in the
order they appear in the array -- so later array elements can act on the results of earlier array
elements.
For example:
<?php
echo preg_replace(
array( '#cat#', '#dog#', '#eel#', '#snowman#' ),
array( 'dog1', 'eel2', 'snowman3', 'monster4' ),
'the good cat and the bad dog wandered on the beach'
);
/* result: the good monster4321 and the bad monster432 wandered on the beach
*/