如何将源html附加到PHP中的DOMElement? [英] How to append source html to a DOMElement in PHP?

查看:177
本文介绍了如何将源html附加到PHP中的DOMElement?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将源代码html添加到DOMElement?这样的:

Is there a way of appending source html into a DOMElement? Something like this:

$trElement->appendSource("<a href='?select_user=4'>Username</a>");

它将解析该片段,然后附加它。

It would parse that fragment and then append it.

推荐答案

您正在寻找

- DOMDocumentFragment :: appendXML - 附加原始XML数据

- DOMDocumentFragment::appendXML — Append raw XML data

手册示例:

$doc = new DOMDocument();
$doc->loadXML("<root/>");
$f = $doc->createDocumentFragment();
$f->appendXML("<foo>text</foo><bar>text2</bar>");
$doc->documentElement->appendChild($f);
echo $doc->saveXML(); 

这篇关于如何将源html附加到PHP中的DOMElement?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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