$dom = new DOMDocument();
$dom->loadHTMLFile('path/to/htmlfile.html'); // or loadHTML($str)
$dom->load('path/to/xmlfile.xml'); // or loadXML($str)
$table = $dom->getElementById('mytable-id'); // DOMElement
$lines = $table->getElementsByTagName('tr'); // DOMNodeList
$links = $dom->getElementsByTagName('a');
$xpath = new DOMXpath($dom);
$tables = $xpath->query("//table[contains(@class,'mytables-class')]");
<?php
require_once('simple_html_dom.php');
function getByClass($element, $class)
{
$content= [];
$html = 'index.html';
$html_string = file_get_contents($html);
$html = str_get_html($html_string);
foreach ($html->find($element) as $element) {
if ($element->class === $class) {
array_push($heading, $element->innertext);
}
}
print_r($content);
}
getByClass("h2", "main");
getByClass("p", "special");