php-html-parser icon indicating copy to clipboard operation
php-html-parser copied to clipboard

Hi, is there a way to set the inner HTML?

Open markusantonwolf opened this issue 5 years ago • 3 comments

I need this to change the inner HTML of a paragraph...

markusantonwolf avatar May 27 '19 10:05 markusantonwolf

Hey @markusantonwolf ,

Can you please give me an example of how you would like this to work? Any idea would be appreciated.

paquettg avatar Aug 18 '19 18:08 paquettg

Hi @paquettg,

for testing I added ->__get() to the object so I was able to change every value. In my case it was 'cause I wanted to change a link and replace the text with the href. Much better for text and html emails....

markusantonwolf avatar Aug 19 '19 10:08 markusantonwolf

Hi, was this ever resolved? can you provide a usage example? thanks!

It would be really nice if there could be a loadStr function for child nodes. Like this:

$dom = new Dom;
$dom->loadStr("<html><body></body></html>");
$dom->find("body")->loadStr("<div id='mydiv'>hello world!</div>");

Of course, we can still use TextNode - BUT - that does not create retrievable nodes:

$dom = new Dom;
$dom->loadStr("<html><body></body></html>");
$body = $dom->find("body")->addChild(new TextNode("<div id='mydiv'><div id='anotherdiv'><b>Hello World!!!</b> how are you?</div></div>"));
echo $dom->find("#anotherdiv")->outerHTML;

causes the error: The collection does not contain any Nodes..

aaharoni avatar Feb 28 '21 20:02 aaharoni