note 19616 deleted from function.preg-replace by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 22:09:23 +0000 |
| Subject: | note 19616 deleted from function.preg-replace by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55717@lists.php.net to get a copy of this message | ||
Note Submitter: bob@valinor.ws
----
I was having trouble getting the preg_replace() function to search a string for {{key}} and replace
it with the value from $row["key"] which was a line of results from a database query. Here
is what I ended up with that does work, and figured someone else might find it useful. I use this so
that I can have a single function that I pass a query and a template to and let it fill in all of
the data.
$new = preg_replace('/{{([A-Za-z]*)}}/e', "\$row['\\1']" ,$format);