3

I have been getting this error when trying to parse HTML with a script tag using PHP's DOMDocument class.

Warning: DOMDocument::loadHTML(): Unexpected end tag : style in Entity, line: 71 in /var/www/signage-dev/dynaml/includes/page.php on line 95

I have even tried CDATA tags but it has resulted in the same error

My script tag is

<script type="text/javascript">
//<![CDATA[
document.write('<style type="text/css"> .printBTN { display: inline; } </style>');
//]]>   
</script>

This snippet is supposed to show a print button when JavaScript is enabled. I don't believe this is the most effective way of doing this (the previous developers created this), but even so, I wish to find a solution to this problem since I may run into this problem again in the future and it may not be as easy to fix as this is.

4

1 回答 1

2

这个问题似乎有解决方案Why split tag when writing it with document.write()?

我猜 php DOM 比大多数浏览器更严格。我有时看到的解决方案是在链接答案下方的评论中发布的解决方案,用<\/script>或 在这种情况下将其转义<\/style>,但我认为只有脚本标签才有必要。

于 2012-04-27T22:11:53.620 回答