I am trying to parse a table and output the a plaintext in another table. I have gotten this far:
<?php
if (url_exists($url))
{
$html = file_get_html($url);
}
else
{
echo "URL doesn't exist.";
}
if ($html && is_object($html) && isset($html->nodes))
{
// Everything checks out
$table = $html->find('table[border]');
if (!empty($table))
{
$row = $table->find('tr');
}
}
else
{
echo "Fetched page is not ok.";
}
?>
This returns an error:
Fatal error: Call to a member function find() on a non-object in /var/www/html/jsudimak/mailman/webdev-test1.php on line 78
Line 78 is this one: $row = $table->find('tr');
This means that :
- the html is valid
- the table I am trying to parse is also valid
Therefore, I am bewildered by the fact that the find() method is still returning this error.
I have looked into the cause of this error extensively for the past few days and I have yet to find a solution. I have also tried some other parsing tools no still no luck. Help me with this fellow debuggers!!!!
By the way, I am using the Simple HTML Dom Parser to parse the table.
$row = $table->find('tr')[0];?$table = $html->find('table[border]')[0];The documentation says that, unless you specify an index in the functionfind(), it will return an array