note 19616 added to function.preg-replace
| From: | bob at valinor dot ws | Date: | Wed, 06 Mar 2002 04:02:53 +0000 |
| Subject: | note 19616 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27390@lists.php.net to get a copy of this message | ||
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);
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+19616
http://master.php.net/manage/user-notes.php?action=delete+19616
http://master.php.net/manage/user-notes.php?action=reject+19616