Can you try for Simple HTML DOM
foreach($html->find('h2') as $element){
$element->class;
}
There are other methods to parse
Method 1.
You can get the H2 tags using the following code snippet, using DOMDocument and getElementsByTagName
$received_str = '<div class="col-sm-9 xs-box2">
<h2 class="title-medium br-bottom">Your Name</h2>
</div>';
$dom = new DOMDocument;
@$dom->loadHTML($received_str);
$h2tags = $dom->getElementsByTagName('h2');
foreach ($h2tags as $_h2){
echo $_h2->getAttribute('class');
echo $_h2->nodeValue;
}
Method2
Using the Xpath you can parse it
$received_str = '<div class="col-sm-9 xs-box2">
<h2 class="title-medium br-bottom">Your Name</h2>
</div>';
$dom = new DOMDocument;
$dom->loadHTML($received_str);
$xpath = new DomXPath($dom);
$nodes = $xpath->query("//h2[@class='title-medium br-bottom']");
header("Content-type: text/plain");
foreach ($nodes as $i => $node) {
$node->nodeValue;
}
$nameis not a string and you can'techoit. Tryprint_rmaybe to check?$name->plaintext. Check PHP Simple Html Dom get the plain text of div