ivopetkov / html5-dom-document-php

A better HTML5 parser for PHP.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

working on fragments?

CanRau opened this issue · comments

is it working on html fragments, too? can't get it working
my html <p>paragraph</p><p>paragraph2</p>
and my php

$dom = new \IvoPetkov\HTML5DOMDocument();
$dom->loadHTML($content);
$paragraphs = $dom->getElementsByTagName('p');
var_dump($paragraphs);

the backslash because my php got another namespace..

The fragments are automatically inserted into a body element, so they work fine. I tested your code on my machine (PHP 7.1 with libxml v2.9.4), and it works great. Can you please share your environment.

got it working now, don't know what happened yesterday..what is the proper/best way to strip the added doctype and body to get the initial fragment? str_replace or are there any other options?

I'd recommend:

$content = $dom->querySelector('body')->innerHTML;

Thanks and sorry for not responding..I had to hold this work for now..