如何在 PHP 中将源 html 附加到 DOMElement?
有没有办法将源 html 附加到 DOMElement 中?像这样的事情:
$trElement->appendSource("<a href='?select_user=4'>Username</a>");
它会解析该片段然后附加它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找
-
DOMDocumentFragment::appendXML
— 追加原始 XML 数据手册示例:
You are looking for
-
DOMDocumentFragment::appendXML
— Append raw XML dataExample from Manual:
如果您在范围内没有对 文档根 的引用,您始终可以通过
ownerDocument
属性:
If you don't have a reference to the document root in scope, you can always access it via the
ownerDocument
property of an arbitrary node:是的,您可以使用
DOMDocument::createDocumentFragment
:在这种情况下,使用普通的
会更简单createElement
调用:在每种情况下,
$element
都是要向其附加代码的 DOM 元素。Yes, you can do this with
DOMDocument::createDocumentFragment
:In this case, it would be simpler to do it with a normal
createElement
call:In each case,
$element
is the DOM element to which you want to append your code.