0

I'm trying to access a H1 tag from a html source I am retrieving with PHP CURL.

The HTML: http://pastebin.com/4ubAhS3E

I'm trying to access the last line (line 63): <h1>Your referrals (5 complete / 0 pending / 9999 total)</h1>

Here is the part of the code that the php simple html dom is using

$result1 = curl_exec ($ch1);
curl_close($ch1);   
echo $result1;


$html = str_get_html($result1);

$main = $html->find('h1', 3); 
foreach($main as $element) 
   echo $element->innertext . '<br>';

But it's just bringing back the whole HTML

BCLtd
  • 1,459
  • 2
  • 18
  • 45
  • `->find()` returns an array only if you didn't specify the 2nd parameter. if you do, it returns a dom node. – Marc B Nov 25 '13 at 18:25

1 Answers1

1

It is easy with DOMDocument, you can fetch the text content inside an element:

$result1 = curl_exec ($ch1);
curl_close($ch1);   
echo $result1;

$dom = new DOMDocument();
$dom->loadHTML($result1);
$xpath = new DOMXpath($dom);

echo $xpath->evaluate('string(//section[@id="your_referrals"]/h1)');
ThW
  • 19,120
  • 3
  • 22
  • 44
  • This is perfect, I have gone around in circles trying to do this. Thanks for taking the time. – BCLtd Nov 25 '13 at 18:37