note 80893 deleted from function.eval by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 19:53:30 +0000 |
| Subject: | note 80893 deleted from function.eval by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155287@lists.php.net to get a copy of this message | ||
Note Submitter: greg at freephile dot com
----
Use the 'e' pattern modifier to evaluate the replacement as PHP code during substitution
in order to put variables in a message template
<?php
$template = '
This is a template with $foo tokens
It also has {new} tokens
';
echo "<pre>$template</pre>";
$foo = blue;
$new = Smarty;
$message = preg_replace('/\\$([\w]+)/e', '$\\1', $template);
$message = preg_replace('/\{([^}]*)}/e', '$\\1', $message);
echo $message;
?>
This is a template with $foo tokens
It also has {new} tokens
This is a template with blue tokens It also has Smarty tokens