Php 重新声明文件\u get\u html()的方法?
我正在使用一个html解析器来提取html,然后对其进行格式化,以便将其插入数据库Php 重新声明文件\u get\u html()的方法?,php,Php,我正在使用一个html解析器来提取html,然后对其进行格式化,以便将其插入数据库 require_once('simple_html_dom.php'); $url = "http://www.site.com/url/params/" $html = file_get_html($url); // The team links are stored in the div.thumbHolder foreach($html->find('.logoWall li') as $e)
require_once('simple_html_dom.php');
$url = "http://www.site.com/url/params/"
$html = file_get_html($url);
// The team links are stored in the div.thumbHolder
foreach($html->find('.logoWall li') as $e)
{
ob_start();
sportPics($e, $league);
}
函数的作用如下:
function sportsPic()
{
require('simple_html_dom.php');
foreach($e->find('a') as $a)
{
// Execute code
}
}
我得到一个错误,读取:
Fatal error: Cannot redeclare file_get_html()
我认为将require()更改为require_once()或将require_once()更改为require会起作用。但事实并非如此。我还认为缓冲区可能会工作,但我对它们的工作原理知之甚少。不要再这样做了-
require('simple_html_dom.php');
在sportsPic()函数中
更新-函数定义函数sportsPic()
不带参数。但是看看这条线-
sportPics($e, $league);
重新定义函数以获取参数
您正在传递参数,但函数无法访问它们,因为它不接受参数。因此,您的$e
是非对象。不要再这样做-
require('simple_html_dom.php');
在sportsPic()函数中
更新-函数定义函数sportsPic()
不带参数。但是看看这条线-
sportPics($e, $league);
重新定义函数以获取参数
您正在传递参数,但函数无法访问它们,因为它不接受参数。因此,您的$e
是一个非对象。将此函数输出为pic()函数
您正在循环中再次调用此函数。将此函数输出到pic()函数中
foreach($html->find('.logoWall li') as $e){
foreach($e->find('a') as $a){
// Execute code
}
}
您正在循环中再次调用此函数。将require
更改为require\u一次
您不需要第二个requireDoing,这会导致:致命错误:调用成员函数find()在非objectchangerequire
到require_一次
您不需要第二个requireDoing:致命错误:在非object上调用成员函数find():致命错误:在非objectdo上调用成员函数find():致命错误:调用成员函数find())关于非对象
foreach($html->find('.logoWall li') as $e){
foreach($e->find('a') as $a){
// Execute code
}
}