A string is always just a string. A string is never a variable.
Case 1, a simple line:
$foo = 'bar'; echo $foo; // bar echo $$foo; // content of $bar if it exists
Case 2, "variable in line":
$foo = 'bar'; $bar = "$foo"; // $bar is now the string 'bar', the variable is interpolated immediately echo $bar; // bar echo $$bar; // bar (content of $bar)
Case 3, a line with a dollar in it:
$foo = '$bar'; echo $foo; // $bar echo $$foo; // invalid variable name "$bar"
$$foo resolves the variable name $$bar , which is an invalid name.
You cannot have "variables in rows". Writing "$foo" immediately interpolates the value of $foo and returns a new line.
Just maybe you want this:
$foo = 'bar'; // the string "bar" $baz = '$foo'; // the string "$foo" // MAGIC echo $baz; // echoes "bar"
Ie, if your string contains a dollar followed by a variable name, you want to replace that value. First, I would say that this is a bad idea. Then I would say that you need to extract all these "dollar strings" from your string, check if the variable exists, and then replace the value in the string using the usual string manipulation. Yes, you could do it using eval , but no, this is not a good idea. For the above code, something like this will do:
if ($baz[0] == '$') { $varName = substr($baz, 1); if (isset($$varName)) { $baz = $$varName; } }