note 40916 deleted from function.preg-replace-callback by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:42:31 +0000 |
| Subject: | note 40916 deleted from function.preg-replace-callback by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127649@lists.php.net to get a copy of this message | ||
Note Submitter: ben at benchun dot net
----
a repost (with correction) of a note originally attributed to matthew at de-construct dot com
(26-Aug-2003 04:48) - a note i found in a compiled help file but which i do not see on this site.
he was missing a stripslashes call in his example, which i have fixed below:
<?
$outer_data = array('foo'=>'abc','bar'=>'123');
$callback = create_function('$matches',
'
$inner_data = unserialize(stripslashes("'. addslashes(serialize($outer_data))
.'"));
// do something here
return $inner_data[$matches[1]];
'
);
$template_data = preg_replace_callback("/\{[$](.*?)\}/", $callback, $template_data);
?>
i found this very useful for implementing a template engine!