note 93831 deleted from function.preg-replace by googleguy

From: Date: Tue, 22 Oct 2013 08:45:02 +0000
Subject: note 93831 deleted from function.preg-replace by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196802@lists.php.net to get a copy of this message
Note Submitter: info at gratisrijden dot nl ---- if you are using the preg_replace with arrays, the replacements will apply as subject for the patterns later in the array. This means replaced values can be replaced again. Example: <?php $text = 'We want to replace BOLD with the <boldtag> and OLDTAG with the <newtag>'; $patterns = array('/BOLD/i', '/OLDTAG/i'); $replacements = array('<boldtag>', '<newtag>'); echo preg_replace ($patterns, $replacements, $text); ?> Output: We want to replace <b<newtag>> with the <<b<newtag>>tag> and <newtag> with the <newtag> Look what happend with BOLD.

« previous php.notes (#196802) next »