开发者

file_get_html displays Fatal Error Call to undefined function

开发者 https://www.devze.com 2023-03-29 14:19 出处:网络
I used the following code to parse the HTML of another si开发者_开发百科te but it display the fatal error:

I used the following code to parse the HTML of another si开发者_开发百科te but it display the fatal error:

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

Fatal error: Call to undefined function file_get_html()


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


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');


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!


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.


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

to get the html content of the page


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


Try file_get_contents.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号