Need Xpath PHP help

Meatytreats

New member
Jul 29, 2011
1,383
35
0
Someone please tell me how to get the innerText here...

I have this on a page I am scraping with a simple PHP script

<FONT COLOR="#FFFFFF">term extension</FONT>
<FONT COLOR="#FFFFFF">expiration</FONT>
<FONT COLOR="#FFFFFF">name</FONT>
<FONT COLOR="#FFFFFF">term length</FONT>

PHP:
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);
$vals = $xpath->evaluate("/html/body//font");



for ($i = 0; $i < $vals->length; $i++) {
    $val= $vals->item($i);
    $output = $val->getAttribute('innerText');
 
    echo "<br />Value: $output ";
}
I've tried like 10 different things, but cant get the innerText or innerHtml...

Yes, I am a n00b when it comes to PHP !
 


So you just want the text and not any attributes of the font tag?

Just get nodeValue of the DomElement in the loop

Code:
$output = $val->nodeValue;
 
  • Like
Reactions: Meatytreats