PHP DOM-加载YouTube嵌入代码时出现问题
我正在尝试执行以下操作:
I'm trying to do the following:
$string = "<object width=\"425\" height=\"350\">
<param name=\"movie\" value=\"http://www.youtube.com/v/1OtdDqF5rnI&autoplay=0\"></param>
<param name=\"wmode\" value=\"transparent\"></param>
<embed src=\"http://www.youtube.com/v/1OtdDqF5rnI&autoplay=0\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed>
</object>";
$doc = new DOMDocument();
$doc->loadXML($string);
当我加载字符串时,出现以下错误:
When I load the string i get the following errors:
[phpBB Debug] PHP Notice: in file /mnt/FS-2/Critical/Media/Private/Website/Online/blitz1up.com/application/controllers/articles.php on line 303: DOMDocument::loadXML() [domdocument.loadxml]: EntityRef: expecting ';' in Entity, line: 2
[phpBB Debug] PHP Notice: in file /mnt/FS-2/Critical/Media/Private/Website/Online/blitz1up.com/application/controllers/articles.php on line 303: DOMDocument::loadXML() [domdocument.loadxml]: EntityRef: expecting ';' in Entity, line: 4
我已将原因缩小到YouTube网址,但不确定解决此错误的最佳方法。因此,任何建议都将受到欢迎。
I have narrowed the cause down to the YouTube URLs but am unsure of the best method to resolve this error. So any suggestions would be most welcome.
URL包含与号,应将其编码为& ; amp;
不用于声明实体。解析器假定& autoload
将启动一个新的实体,但它永远不会以分号终止。
The URLs contain ampersands, which should be encoded as &
when not used for declaring entities. The parser assumes &autoload
will start a new entitiy but it is never terminated with a semicolon.
要使用HTML,请考虑使用 loadHTML()
加载片段;并禁用该部分的错误:
For working with the HTML, consider loading the fragment with loadHTML()
; and disable errors for that part:
libxml_use_internal_errors(TRUE);
$doc = new DOMDocument();
$doc->loadHTML($string);
libxml_clear_errors();
echo $doc->saveHTML();
上面的方法也可以用于 loadXML
。
The above would work with loadXML
too.