Re: parsing variables inside a variable?
| From: | Justin Patrin | Date: | Fri, 30 Jan 2004 00:49:56 +0000 |
| Subject: | Re: parsing variables inside a variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-176285@lists.php.net to get a copy of this message | ||
Jimbo wrote:
I query and use mysql_fetch_array to get the data into an associative array. I then build a string and output it like this: echo "blah blah ".$row["thecolumn"]." blah blah";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. -- paperCrane <Justin Patrin>