note 20214 added to function.preg-replace
| From: | cbakerATcbakerDOTorg at php2 dot chek dot com | Date: | Tue, 26 Mar 2002 18:47:19 +0000 |
| Subject: | note 20214 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28241@lists.php.net to get a copy of this message | ||
Since, as far as I can tell, the preg_replace() replacement parameter can't deal with using $1
as a key in an existing hash, here's an ugly hack that does just that:
$string = "asdf[[foo]]asdf[[bar]]asdf";
$args = array("foo"=>"BAR",
"bar"=>"PACO");
while(preg_match("/^(.*)\[\[(\w+)\]\](.*)$/", $string, $match)) {
$string = $match[1] . $args[$match[2]] . $match[3];
}
It would be nice if $string = preg_replace("/\[\[(\w+)\]\]/", $args["$1"],
$string); worked but it don't.
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+20214
http://master.php.net/manage/user-notes.php?action=delete+20214
http://master.php.net/manage/user-notes.php?action=reject+20214