Replace string with $var of the same name
Posted: Wed Apr 12, 2006 6:55 am
Hiya, my first post here!
Building a very simple CMS and want a way for the layout pages to insert whatever bits of the content they require.
For example [_title] inserts the title, [_lastmod] the date the page was last modified, etc. All these are fetched from mysql as an array at the moment and are sorted using str_replace, but hardcoding every field of data is a bit tedius.
I would like to use the following to change any [_varname] to whatever is stored in $varname.
preg_replace("/\[_(\w*)\]/", "\$$1", $layout[0]);
\$$1 simply prints '$varname' obviously, not quite what im looking for!
many thanks.
Building a very simple CMS and want a way for the layout pages to insert whatever bits of the content they require.
For example [_title] inserts the title, [_lastmod] the date the page was last modified, etc. All these are fetched from mysql as an array at the moment and are sorted using str_replace, but hardcoding every field of data is a bit tedius.
I would like to use the following to change any [_varname] to whatever is stored in $varname.
preg_replace("/\[_(\w*)\]/", "\$$1", $layout[0]);
\$$1 simply prints '$varname' obviously, not quite what im looking for!
many thanks.