I have this HTML template:
<center>
<img src="image1">
<br><br>
<img src="image2">
<br><br>
<strong><em>TITLE1 :</em></strong> DESC1<br>
<strong><em>TITLE2 :</em></strong> DESC2<br>
<strong><em>TITLE3 :</em></strong> DESC3<br>
<strong><em>TITLE4 :</em></strong> DESC4<br>
<strong><em>TITLE5 :</em></strong> DESC5<br><br><br>
<img src="image3">
<br><br><br>DESC_GEN
</center>
I want to use xpath to get this expected result:
TITLE 1 = DESC 1
TITLE 2 = DESC 2
TITLE 3 = DESC 3
TITLE 4 = DESC 4
TITLE 5 = DESC 5
general = DESC_GEN
In an array so i can use the values elsewhere in my code.
This is what I have tried:
$dom = new DOMDocument();
$dom->loadHTML($html_string);
$xpath = new DOMXpath($dom);
$elements = $xpath->query("//em");
foreach($elements as $e) {
echo $e->nodeValue . '<br/>';
}
But unfortunatelly this returns only TITLE 1, TITLE 2, TITLE 3 etc.
I want get their respective values (In this case DESC 1, DESC 2 etc ...).
What is the approach I can take to achieve this goal?