This php library contains an instrumentary to work with html document.You can work with dom and find elements and text.You can also get commentaries from dom, if you want.
To create a Parser object you need to include this library to your project:
use Parser\Dom as Dom;
$html = new Dom('url or href to file');
You can look the dom using this:
print_r($html->dom());
You can also look source file code using this:
print_r($html->dump(string $filename)); //You can indicate file where will be writen dump file.
You can also look html that was finded by url:
echo $html->read();
To find element, you can this two functions:
$html->find('elem', 1); //You can indicate what element with tag "elem" you want to get
$html->children(1);
$html->children(1)->viewDom(); //you can use this method to see the result that will finded by script.
First method finds tag with name "elem".You can also find elements by class or id.You can do it, marking element by special symbols "." or "#".
Second method finds second children in your main dom("head" at example) and all his childs.
You can also use this method together:
$html->find('head')->children(0); //It can be link
You can find text easily using this method:
$html->plainText();
It return the array with text from all elements childrens.
Its not a problem.The script solve all the problems that can be in your document.But there are differences with that how browser solve the problems and this script.Lets see:
№1 What about tags, who dont closing or opening?
Script finds tags who dont opening or closing and fix it.
№2 Hmm, okay, then what if tags closing wrongly?
Lets take this html:
<span>
<p>
</span>
</p>
Thats how my script handles something like that:
<span>
<p>
</p>
</span>
Please see the LICENSE for more info.