note 40916 added to function.preg-replace-callback

From: Date: Fri, 19 Mar 2004 01:19:59 +0000
Subject: note 40916 added to function.preg-replace-callback
Groups: php.notes 
Request: Send a blank email to php-notes+get-67041@lists.php.net to get a copy of this message
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! ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40916 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40916&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40916&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67041) next »