The variable $a below does not seem to parse properly when if I attempt to declare it using a heredoc. It however, does work when I define it with the simple = declaration method. I would like to be able to define it as a heredoc, because a lot of HTML code must be called all at once, and in this example I have just simplified it for demonstrative purposes.
$a = "<a href = \'http://www.google.com\'>Google</a>";
echo "
<div id = \"test\"
ondblclick = \"document.getElementById('test').innerHTML = '$a';\">
Change Event
</div>
";
// when the user clicks the text "Change Event",
// it should turn into whatever $a is, in this case a link to Google
The previous code works, however when I try to convert it to a heredoc, something does not parse correctly.
I have tried using four kinds of quote styles, “, \”, ‘, and \’
\’ is the quote style required by where the variable lies in the code, within JavaScript, as the other three styles have already been used, and it is the quote that works (obviously) when I am declaring a variable in a simple (=) way.
When I use ” or \” the code yields:

When I use ‘ or \’ the code yields:

In both cases, the ondblclick functionality does not work either. I am not sure what is going wrong and why heredoc is not parsing the way it seems like it should.
Here is one of my attempt at making the heredoc; the only difference between my attempts are the quote styles around the link.
$a = <<<EOT
<a href = \'http://www.google.com\'>Google</a>
EOT;
// as stated above, I have tried ", \", ', and \'
Hmmm trying to think of a way around this whilst still using
heredoc… the double quotes within .innerHTML must be escaped when printed to the browser, or you get the problem you have. Some browsers will be kind and automatically escape them but on the whole they won’t and, if truth be told, they shouldn’t.The only way I can get this code to work is by removing the “” from the href attribute completely.
It’s really not recommended to have .innerHTML used this way as the
<a>tag now contains technically invlalid HTML, but it seems to work in Firefox,IE 9 (quirks mode on and off) and Chrome.