From: "Justin Patrin" <[EMAIL PROTECTED]> > >>What you need to understand is that the string parsing for variables > >>only happens when the string is actually in your script. When you > >>dynamically create a string (or get it from a DB) it's just a string of > >>characters in memory and is *not* parsed. > >> > >>To do something like this, you would have to use one of a few things. > >>The first would be to use some kind of search and replace to replace > >>those variables with what you really want. > >> > >>$text = str_replace('$name', $name, $text); > >> > >>That's fairly simple and could even be done for multiple variables. > >> > >>foreach(array('name', 'price') as $varName) { > >> //yes, the $$ is correct > >> $text = str_replace('$'.$varName, $$varName, $text); > >>} > >> > >>You could also use a regular expression if you *really* wanted to, but > >>what's above is easier.
For a regular expression example of how to do this: <?php $str = 'this is $name a $test'; $name = 'John'; $test = 'foobar'; $evaled_str = preg_replace('/\$([a-z0-9_]+)/ie','\$\1',$str); echo $evaled_str; ?> Where "$str" is what's retrieved from the database with the "variables" in it. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php