Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple HTML Dom Parser: How to insert to elements

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?

like image 309
Dayo Avatar asked Sep 03 '12 18:09

Dayo


1 Answers

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.

like image 116
Dayo Avatar answered Oct 27 '22 16:10

Dayo