加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php domdocument创建自我关闭标记,打破html

发布时间:2020-12-13 17:26:14 所属栏目:PHP教程 来源:网络整理
导读:参见英文答案 Self-closing tags using createElement????????????????????????????????????2个 我正在解析用户输入文本使用正则表达式将youtube网址转换为iframe,因此我最终得到以下信息: iframe title="YouTube video player" width="640" height="370" s
参见英文答案 > Self-closing tags using createElement????????????????????????????????????2个
我正在解析用户输入文本&使用正则表达式将youtube网址转换为iframe,因此我最终得到以下信息:

<iframe title="YouTube video player" width="640" height="370" src="http://www.youtube.com/embed/*id*" frameborder="0" allowfullscreen></iframe>

然后通过DOMdocument()解析文本,该文件将上述内容转换为自闭标签:

<iframe class="EmbeddedVideo" title="YouTube video player" width="640" height="370" src="http://www.youtube.com/embed/xP4HhaUMB3I" frameborder="0" allowfullscreen=""/>

这打破了Chrome和&amp ;;歌剧.如果我手动将html更改回:

<iframe class="EmbeddedVideo" title="YouTube video player" width="640" height="370" src="http://www.youtube.com/embed/xP4HhaUMB3I" frameborder="0" allowfullscreen=""></iframe>

有用.

首先,自闭标签有什么问题(因为我看不到任何东西)?

有没有办法强制domdocument()使用’正确’的结束标记?

解决方法

您可以使用选项 LIBXML_NOEMPTYTAG

$doc->saveXML($node,LIBXML_NOEMPTYTAG);

这将强制扩展< iframe />到< iframe>< / iframe>

但是,您也可以使用saveHTML()(首选).这将正确保留HTML标记:

$doc->saveHTML();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读