I have a HTML file formatted like this:
<p class="p1">subject</p>
<p class="p2">detail <span>important</span></p>
<p class="p1">subject</p>
<p class="p2">detail<span>important</span></p>
I wrote a PHP code to automatically get each p1 and it's detail to insert them into my mysql table.
this is my code:
$doc = new DOMDocument();
$doc->loadHTMLFile("file.html");
$xpath = new DomXpath($doc);
$subject = $xpath->query('//p');
for ($i = 0 ; $i < $subject->length-1 ; $i ++) {
if ($subject->item($i)->getAttribute("class") == "p1")
echo $subject->item($i)->nodeValue;
}
...
This is not my full code, but the problem is:
echo $subject->item($i)->nodeValue;
Which gives me <p>detail important</p>, without the <span></span> tag.
It is so important to have the span tags around the "important" part of the detail. is there any function which can do that without getting headache?
Thanks in advance