How do I get a PHP variable between single quotes?

Mark picture Mark · Feb 4, 2010 · Viewed 11.7k times · Source

How can I get the value $fbAppPath into the PHP statement below?

<? print json_encode(array(array('text' => 'Become A Fan', 'href' => '$fbAppPath'))); ?>

Answer

Tyler Carter picture Tyler Carter · Feb 4, 2010

You cannot get a variable in a single quote string. PHP interprets all single-quoted strings EXACTLY as they appear. (aside from escaping a single quote)

The ONLY way to get a variable while using single quotes is to break out of them:

$foo = 'variable';
echo 'single-quoted-string-'.$foo.'-more-single-quoted-string';