Simple HTML Dom Parser: How to insert to elements

浪尽此生 提交于 2019-12-04 12:27:17

问题


I am trying to insert (append) into an element ... "body" specifically.

I am able to do this this way at the moment:

$var = "some JS stuff";
$e = $htmlDOM->find("body", 0);
$e->outertext = '<body>' . $e->innertext . $var . '</body>';

My issue is that this fixes <body> but the actual html might have js or id etc attached to <body> and I will like to maintain that if it is the case.

The docs don't seem to show a method for this.

Is it possible?


回答1:


After looking at the source code, I found that the way to go about it is to use

$var = "some JS stuff";
$e = $htmlDOM->find("body", 0);
$e->outertext = $e->makeup() . $e->innertext . $var . '</body>';

That is, the undocumented makeup() function will build the tag and any associated text/code.



来源:https://stackoverflow.com/questions/12252843/simple-html-dom-parser-how-to-insert-to-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!