PHP DOM-加载YouTube嵌入代码时出现问题 [英] PHP DOM - Problem loading YouTube Embed Code

查看:76
本文介绍了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 &amp; 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.

这篇关于PHP DOM-加载YouTube嵌入代码时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆