From: Andrew Ballard on
On Tue, Jun 8, 2010 at 2:50 AM, Raymond Irving <xwisdom(a)gmail.com> wrote:
> Well it actually failed when loadHTML() is used.
> The strange thing is that it will fail regardless of the "--" characters:
>
> "Unexpected end tag : strong in Entity"
>
> __
> Raymond Irving

What failed? I copied your example and pasted it into a new file in
Zend Studio and it ran without any errors or warnings when I changed
loadXML to loadHTML. It WILL fail if you use loadXML unless the
contents of the script are properly enclosed in a CDATA section
because a script tag has no meaning in regular XML.

I don't know if you have control over the XHTML code or not, but if
you want to use loadXML for the document in your example, it should
look like this, based on what I have read on the web:

<?php
$html = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<script type="text/javascript">
// <![CDATA[
var i = 0, html = "<strong>Bold Text</strong>,Normal Text";
document.write(html);
i--; // this line causes the parser to fail
alert(html);
// ]]>
</script>
</body>
</html>';
$dom = new DOMDocument();
$dom->loadXML($html);
echo $dom->saveHTML();
?>

Andrew