php file_get_html 显示对未定义函数的致命错误调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7124823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:04:18  来源:igfitidea点击:

file_get_html displays Fatal Error Call to undefined function

php

提问by Sathish Kumar

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

我使用以下代码来解析另一个站点的 HTML,但它显示了致命错误:

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

Fatal error: Call to undefined function file_get_html()

致命错误:调用未定义的函数 file_get_html()

回答by mkk

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

你确定你已经下载并包含了php simple html dom parser吗?

回答by khaled

You are calling class does not belong to php.

您正在调用的类不属于php.

Download simple_html_domclass hereand use the methods included as you like it. It is really great especially when you are working with Emails-newsletter:

在此处下载simple_html_dom类并根据需要使用包含的方法。这真的很棒,尤其是当您使用 Emails-newsletter 时:

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

回答by cwallenpoole

It looks like you're looking for simplexml_load_filewhich will load a file and put it into a SimpleXMLobject.

看起来您正在寻找simplexml_load_file哪个将加载文件并将其放入SimpleXML对象中。

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.

当然,如果格式不正确可能会导致问题。你的另一个选择是DomObject::loadHTMLFile。这对格式不正确的文件更加宽容。

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

如果您不关心 XML 并且只想要数据,您可以使用file_get_contents.

回答by Grigor

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

to get the html content of the page

获取页面的html内容

回答by Rahul Kaundal

in simple words

用简单的话

download the simple_html_dom.php from here Click here

从这里下载 simple_html_dom.php点击这里

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

现在将这些行写入您的 PHP 文件 include_once('simple_html_dom.php'); 然后开始你的编码 $html = file_get_html(' http://www.google.co.in'); 不会显示错误

回答by Rahul Kaundal

As everyone have told you, you are seeing this error because you obviously didn't downloaded and included simple_html_domclass 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,

正如每个人都告诉你的,你看到这个错误是因为你simple_html_dom在复制粘贴第三方代码后显然没有下载和包含类,现在你有两个选项,选项一是所有其他开发人员在他们的答案中提供的和我的,

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!

选项二是根本不使用该第三方 php 类!并且使用php开发者的默认类来执行同样的任务,并且那个类总是加载php,所以使用这个方法也有效率,原创性和安全性!

Instead of file_get_htmlwhich not a function defined by php developers use-

file_get_html不是由 php 开发人员定义的函数使用 -

$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)

$doc = new DOMDocument(); $doc->loadHTMLFile("filename.html"); echo $doc->saveHTML();这确实是由他们定义的。在 php.net/manual 上检查(由其开发人员提供的原始 php 手册)

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....

这会将 HTML 放入一个 DOM 对象中,该对象可以通过单独的标签、属性等进行解析。这是一个从“a”标签中获取所有“href”属性和相应节点值的示例。很酷....

$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!

PS:如果你喜欢我的回答,请点赞,这将有助于我在 STACKOVERFLOW 上的声誉,这些人认为我是菜鸟!