Re: Variable within a Variable
| From: | Chris | Date: | Mon, 10 Apr 2006 02:14:19 +0000 |
| Subject: | Re: Variable within a Variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233645@lists.php.net to get a copy of this message | ||
bob pilly wrote:
Hi All Im trying to store a document template in mysql that has php var names within it and then find it in the datebase and print it out with the var names replaced with the var values. e.g i have this stored Dear $title $name we would like to...... I declare the vars $title and $name $title = 'Mr'; $name = 'Test'; //retrieve the stored template $query = "select template from letters"; $result = mysqli_query($dblink,$query); if($row = mysqli_fetch_array($result)){If you don't get an immediate response you don't need to repost your question. The data stored in the database is $title, $name, not the filled in variables. When php prints it out (in this case), it's printing it out exactly how it came out of the database. No variable substitutions etc take place unless you tell them to. I'd suggest using htmlentities / htmlspecialchars to help make sure your data won't cause issues like XSS. You could do: print str_replace(array('$title', '$name'), array($title, $name), htmlentities($row['template'])); -- Postgresql & php tutorials http://www.designmagick.com/print $row['template'];} i would expect that to print: Dear Mr Test we would like to...... but it doesnt it prints out Dear $title $name we would like to......