file_get_html displays Fatal Error Call to undefined function
Asked Answered
C

7

15

I used the following code to parse the HTML of another site but it display the fatal error:

$html=file_get_html('http://www.google.co.in');

Fatal error: Call to undefined function file_get_html()

Crocked answered 19/8, 2011 at 16:49 Comment(1)
try to read and understand error textHandbill
C
46

are you sure you have downloaded and included php simple html dom parser ?

Cardiology answered 19/8, 2011 at 16:51 Comment(0)
K
11

You are calling class does not belong to php.

Download simple_html_dom class here and use the methods included as you like it. It is really great especially when you are working with Emails-newsletter:

include_once('simple_html_dom.php');
$html = file_get_html('http://www.google.co.in');
Keep answered 10/4, 2014 at 17:7 Comment(0)
T
4

As everyone have told you, you are seeing this error because you obviously didn't downloaded and included simple_html_dom class after you just copy pasted that third party code, Now you have two options, option one is what all other developers have provided in their answers along with mine,

However my friend,

Option two is to not use that third party php class at all! and use the php developer's default class to perform same task, and that class is always loaded with php, so there is also efficiency in using this method along with originality plus security!

Instead of file_get_html which not a function defined by php developers use-

$doc = new DOMDocument(); $doc->loadHTMLFile("filename.html"); echo $doc->saveHTML(); that's indeed defined by them. Check it on php.net/manual(Original php manual by its devs)

This puts the HTML into a DOM object which can be parsed by individual tags, attributes, etc.. Here is an example of getting all the 'href' attributes and corresponding node values out of the 'a' tag. Very cool....

$tags = $doc->getElementsByTagName('a');

foreach ($tags as $tag) {
       echo $tag->getAttribute('href').' | '.$tag->nodeValue."\n";
}

P.S. : PLEASE UPVOTE IF YOU LIKED MY ANSWER WILL HELP MY REPUTATION ON STACKOVERFLOW, THIS PEOPLES THINK I'M NOOB!

Tap answered 22/12, 2018 at 20:9 Comment(0)
C
3

It looks like you're looking for simplexml_load_file which will load a file and put it into a SimpleXML object.

Of course, if it is not well-formatted that might cause problems. Your other option is DomObject::loadHTMLFile. That is a good deal more forgiving of badly formed documents.

If you don't care about the XML and just want the data, you can use file_get_contents.

Combat answered 19/8, 2011 at 16:57 Comment(0)
U
1
$html = file_get_contents('http://www.google.co.in');

to get the html content of the page

Undercharge answered 19/8, 2011 at 16:51 Comment(0)
E
1

in simple words

download the simple_html_dom.php from here Click here

now write these line to your Php file include_once('simple_html_dom.php'); and start your coading after that $html = file_get_html('http://www.google.co.in'); no error will be displayed

Etna answered 26/12, 2016 at 2:10 Comment(0)
O
0

Try file_get_contents.

http://www.php.net/manual/en/function.file-get-contents.php

Ontario answered 19/8, 2011 at 16:52 Comment(1)
he is looking for a parser as well as getting the htmlAmaze

© 2022 - 2024 — McMap. All rights reserved.