note 80893 added to function.eval
| From: | greg at freephile dot com | Date: | Tue, 05 Feb 2008 21:44:17 +0000 |
| Subject: | note 80893 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135804@lists.php.net to get a copy of this message | ||
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
----
Server IP: 208.69.120.35
Probable Submitter: 65.211.1.194
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- https://master.php.net/note/edit/80893
Del: integrated -- https://master.php.net/note/delete/80893/integrated
Del: useless -- https://master.php.net/note/delete/80893/useless
Del: bad code -- https://master.php.net/note/delete/80893/bad+code
Del: spam -- https://master.php.net/note/delete/80893/spam
Del: non-english -- https://master.php.net/note/delete/80893/non-english
Del: in docs -- https://master.php.net/note/delete/80893/in+docs
Del: other reasons-- https://master.php.net/note/delete/80893
Reject -- https://master.php.net/note/reject/80893
Search -- https://master.php.net/manage/user-notes.php