note 23519 added to function.preg-replace
| From: | chenATvbulletinDOTorg@php.net | Date: | Sat, 20 Jul 2002 10:11:12 +0000 |
| Subject: | note 23519 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33335@lists.php.net to get a copy of this message | ||
In response to cbakerATcbakerDOTorg:
> It would be nice if $string =
> preg_replace("/\[\[(\w+)\]\]/",
> $args["$1"], $string); worked but it don't.
You can do just that using the 'e' modifier:
<?php
$string = 'asdf[[foo]]asdf[[bar]]asdf';
$args = array(
'foo' => 'BAR',
'bar' => 'PACO'
);
$string = preg_replace('#\[\[(\w+)\]\]#e', '$args["$1"]', $string);
?>
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+23519
http://master.php.net/manage/user-notes.php?action=delete+23519
http://master.php.net/manage/user-notes.php?action=reject+23519