0

I've been getting this error code whilst trying to get the A tags from a URL: "Fatal error: Uncaught Error: Call to a member function find() on string in (filename) Stack trace: #0 {main} thrown in (filename) line 9."

This is my code.

<?php
// Include the library
include('simple_html_dom.php');

// Retrieve the DOM from a given URL
$html = file_get_contents('https://www.google.com');

// Find all "A" tags and print their HREFs
foreach($html->find('a') as $e);

echo $e->href . '<br>';
?>

I have seen 1-2 questions with the same error on StackOverflow, just none of them have solved my issue which is why I've resorted to asking myself.

Matt H
  • 91
  • 6
  • 1
    `file_get_contents` should be `file_get_html` – Barmar Jun 13 '18 at 21:10
  • @barmar, thanks for your response. When I do this, I get the following three errors: Warning: file_get_contents(): stream does not support seeking in (myfile) on line 76 -- Warning: file_get_contents(): Failed to seek to position -1 in the stream in (simple_html_dom.php file) on line 76 -- Fatal error: Uncaught Error: Call to a member function find() on boolean in (myfile) Stack trace: #0 {main} thrown in (myfile) on line 9 – Matt H Jun 13 '18 at 21:17
  • See https://stackoverflow.com/questions/42685814/file-get-contents-stream-does-not-support-seeking-when-was-php-behavior-abo?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Barmar Jun 13 '18 at 21:42

0 Answers0