Page is a not externally linkable
vincevincevince - 11:07 am on Sep 12, 2007 (gmt 0)
The str_replace would probably be faster for some cases, although it would depend upon the number of tags to be replaced. On the positive side for the str_replace, it would be more secure if you didn't have control over your .tpl file. One difference in end result is that with the preg_replace method, a tag enclosed in {} but not matched by a variable will be removed ("Hello {name}!" => "Hello!"), whereas the str_replace method would leave that unreplaced tag in place ("Hello {name}!" => "Hello {name}!")
> why not use str_replace
Exactly as dmorison said - to make it generic. It's not normally expected that you have to list the tags which you're going to use. Although, if all fields are defined within an array such as $values['{title}'], $values['{header}'], etc. then you could use array_keys($values) and $values as the arguments to your str_replace making it more generic.