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

1
  • ->find() returns an array only if you didn't specify the 2nd parameter. if you do, it returns a dom node. Commented Nov 25, 2013 at 18:25

1 Answer 1

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)');
Sign up to request clarification or add additional context in comments.

1 Comment

This is perfect, I have gone around in circles trying to do this. Thanks for taking the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.