note 29267 deleted from function.preg-replace by sniper

From: Date: Tue, 30 Sep 2003 12:31:53 +0000
Subject: note 29267 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57478@lists.php.net to get a copy of this message
Note Submitter: freesoftware@xs4all.nl ---- [quote]If pattern is an array and replacement is a string, then this replacement string is used for every value of pattern. The converse would not make sense, though.[/quote] Well, I have a case where it does make sense. In an application I have written support for the [pre] tag that suppresses anything in between from being parsed by regular expressions. I could have added a check in every expression to see if there are [pre] tags between them, but came up with the following: 1st expression: preg_match_all('/\[pre\](.+)\[\/pre\]/Uis', $content, $prematches); this stores all matches of content in between [pre] [/pre] in the array $prematches. Now I do the normal parsing bit, and afterwards actually wanted to do this: $content = preg_replace('/\[pre\](.+)\[\/pre\]/Uis', $prematches, $content); which doesn't do the trick, but this does: $i=0; $content = preg_replace('/\[pre\](.+)\[\/pre\]/Uise', "\$prematches[1][\$i++]", $content);

« previous php.notes (#57478) next »