I’m quite new to programming in PHP and I might have some simple problems, but I haven’t found the answer yet over here.
I want to use PHP to obtain the text between the tags and used Simple HTML DOM for this.
My code looks like this :
$html = file_get_contents($base_url . $menu_url);
//print($html);
$students = array();
foreach($html->find('a') as $element) {
$students[] = $element->plaintext;
}
But when I run this code it gives me:
PHP Fatal error: Call to a member function find() on a non-object in <location> on line <x>
Any clear mind who could correct me?
The variable
$htmlis a string and not an object. So you can’t call methods on it. If you want to parse Html have look around Stackoverflow there are a lot of examples. E.g. How do you parse and process HTML/XML in PHP? and Best XML Parser for PHP.