Simple HTML parser: how to insert elements

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

I can do it this way at the moment:

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

My problem is that this fixes <body>, but the actual html may have js or id, etc. attached to <body>, and I would like to support this if that is the case.

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

Is it possible?

+5
source share
1 answer

After looking at the source code, I found that you need to use

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

That is, an undocumented function makeup()will create a tag and any associated text / code.

+12
source

All Articles