PHP, quotes, and squiggly brackets

Posted Thursday, August 7, 2008 at 12h43 in Personal

I’m writing a web application that requires me to use PHP to output Javascript code, and one of my lines is the following:

echo “fund.Data={$ydata};\n”;

This caused a Javascript error, which didn’t make sense to me until I realized that the squiggly brackets weren’t being printed, so the output was actually:

echo “fund.Data=$ydata;\n”;

This was strange, because squiggly brackets aren’t the type of characters you normally escape in a double-quoted string.  However, if placed around a variable name, they apparently mean something special and aren’t printed.  So in the end, I just broke up the string:

echo “fund.Data={” . “$ydata};\n”;

And that worked fine.