How can I get the value of $fbAppPath into the PHP statement below?
<? print json_encode(array(array('text' => 'Become A Fan', 'href' => '$fbAppPath'))); ?>
How can I get the value of $fbAppPath into the PHP statement below?
<? print json_encode(array(array('text' => 'Become A Fan', 'href' => '$fbAppPath'))); ?>
<? print json_encode(array(array('text' => 'Become A Fan', 'href' => $fbAppPath))); ?>
Or
<? print json_encode(array(array('text' => 'Become A Fan', 'href' => "more text ${fbAppPath} more text"))); ?>
if you wanted to embed the variable value in a string. The double quotes are important in that case.
Ok, I figured it out... I didn't realize I was in a function and referencing a variable outside the function... sorry to waste anyone's time
<? print json_encode(array(array('text' => 'Become A Fan', 'href' => $GLOBALS['fbAppPath']))); ?>
variable being referenced was in the global scope..
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';
You do not need quotes around a variable that is already a string.
'I am a string, because I am surrounded by quotes';
$string = 'I am a string, because I am surrounded by quotes';
if (is_string($string)) {
echo 'Yes, the variable $string is a string, because it contains a string';
}
$anotherString = $string;
if (is_string($anotherString)) {
echo 'The variable $anotherString is a string as well, because it contains a string as well';
}
$notWhatYouExpect = '$string';
echo $notWhatYouExpect; // outputs the word '$string'