I try to display the content of Wikipedia infobox using simple Dom Parser but it gives me problem. this is the code.`
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
//The folder where you uploaded simple_html_dom.php
require_once('simple_html_dom.php');
//Wikipedia page to parse
$html = file_get_html('https://en.wikipedia.org/wiki/Burger_King');
foreach ( $html->find ( 'table[class=infobox vcard]' ) as $element ) {
$cells = $element->find('td');
$i = 0;
foreach($cells as $cell) {
$left[$i] = $cell->plaintext;
if (!(empty($left[$i]))) {
$i = $i + 1;
}
}
$cells = $element->find('th');
$i = 0;
foreach($cells as $cell) {
$right[$i] = $cell->plaintext;
if (!(empty($right[$i]))) {
$i = $i + 1;
}
}
print_r ($right);
echo "<br><br><br>";
print_r ($left);
//If you want to know what kind of industry burger king is
//echo "Burger king is $right[2], $left[2]
}
?>
</body>
</html>
The code is not working on any other pages like https://en.wikipedia.org/wiki/United_Kingdom, it works ony using https://en.wikipedia.org/wiki/Burger_King. this is the error message I am getting Fatal error: Call to a member function find() on a non-object in C:\wamp\www\MyApps\Inbox.php on line 16