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 \'