[thelist] PHP - Variables in a literal string

Anthony Baratta Anthony at Baratta.com
Sat Jun 2 00:58:49 CDT 2001


At 10:37 PM 6/1/2001, you wrote:

>I'm stuck with that literal string, that's a fact. I was wondering how to
>force PHP to parse it.

Stolen from: http://www.php.net/manual/en/function.eval.php

<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.<br>';
echo $str;
eval ("\$str = \"$str\";");
echo $str;
?>

The above example will show:

This is a $string with my $name in it.
This is a cup with my coffee in it.

Hope this helps....
---
Anthony Baratta
President
Keyboard Jockeys





More information about the thelist mailing list