note 29267 added to function.preg-replace
| From: | freesoftware at xs4all dot nl | Date: | Fri, 07 Feb 2003 18:41:15 +0000 |
| Subject: | note 29267 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43579@lists.php.net to get a copy of this message | ||
[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);
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+29267
http://master.php.net/manage/user-notes.php?action=delete+29267
http://master.php.net/manage/user-notes.php?action=reject+29267