Why isn't this EOF javascript code appearing in the html when it is echoed?
In this php code I use the heredoc EOF to insert some javascript:
$room= <<<EOF
<script type="text/javascript" charset="utf-8">
test;
</script>
EOF;
when I try to echo $room it doesn't appear:
echo "<li style=\"text-align: center;\"><img src=\"example.com\" width=\"264\" height=\"198\" alt=\"\" /> $room</li>";
($room doesn't appear in the html).
however if I do the same with:
$room= <<&开发者_开发问答lt;EOF
test;
EOF;
Then the word test gets echoed in my list html element.
EDIT - to clarify, nothing appears in the source of the html when I do the first echo attempt (the list appears, but no script tags or test inside it).
<script type="text/javascript" charset="utf-8">
test;
</script>
basically means nothing to javascript. I'd guess you want (in a sense of outputting anything at least):
<script type="text/javascript" charset="utf-8">
document.write('test');
</script>
If you literally want to display the script tag, try:
echo '<li style="text-align: center;"><img src="example.com" width="264" height="198" alt="" />', htmlspecialchars($room), '</li>';
精彩评论