0

I would like to parse an HTML file in order to extract some information.

My code is:

$url = 'http://localhost/myFiles/';
$response = file_get_contents($url);

$html = new simple_html_dom();
$html->load_file($response);
if (!empty($html)) {
    foreach($html->find('tr td a') as $a) {
        echo $a->href.", ";
    }
}

As I can see, $response is a string and not an html file. That's why I get error message: Call to a member function find() on a non-object.

2
  • Try using json_decode($response, true); It should create a json array of your string. Commented Jun 9, 2015 at 14:21
  • "It's a string" – Well yes, HTML is a string. What does that string contain?! Commented Jun 9, 2015 at 14:35

1 Answer 1

1

You can choose to load htmls instead of contents as follows

   $url = 'http://localhost/myFiles/';

   $html = file_get_html($url);
   foreach($html->find('tr td a') as $a) {
      echo $a->href.", ";
    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.