Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对成员函数find()的PHP调用_Php_Parsing - Fatal编程技术网

对成员函数find()的PHP调用

对成员函数find()的PHP调用,php,parsing,Php,Parsing,代码: require_once('simple_html_dom.php'); $file = 'http://testwork.ru/Tempp/domains.php'; // page with table $SymbolsCountMin = 0; $SymbolsCountMax = 10; $SymbolsBackLis = array('-','_','.','0','1','2','3','4','5','6','7','8','9'); $ArrTr = array(

代码:

require_once('simple_html_dom.php');

$file = 'http://testwork.ru/Tempp/domains.php'; // page with table

$SymbolsCountMin = 0;
$SymbolsCountMax = 10;

$SymbolsBackLis = array('-','_','.','0','1','2','3','4','5','6','7','8','9');

$ArrTr = array();
$ArrTd = array();

$ch = curl_init($file);

curl_setopt($ch, CURLOPT_URL, $file );

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/x-www-form-urlencoded'
    ));

    $html = curl_exec($ch);
    //$responseInfo = curl_getinfo($ch);
    curl_close ($ch);

    //var_dump($html);

//$html = file_get_html('http://testwork.ru/Tempp/domains.php');

// Find all tr 
$row = 0;
foreach($html->find('tr') as $tr){
    if($row!=0){
        $row++;
        $column = 0;
        foreach($tr->find('td') as $td){
            $column++;
            $text = $td->plaintext;

            $ArrTd[$column] = $text;
        }
    }
    if(iconv_strlen($ArrTd[0]) > $SymbolsCountMin && iconv_strlen($ArrTd[0]) < $SymbolsCountMax && !in_array($ArrTd[0], $SymbolsBackList)){
        $ArrTr[$row] = $ArrTd;
    }
}

$c = '';

foreach($ArrTr as $arr_tr =>$ftr){
    $c .='<tr>';
    foreach($ftr as $arr_td =>$ftd){
        $c .='<td>';
        $c .= $ftd;
        $c .='<td>';
    }
    $c .='</tr>';
}

$row_header = '    
<table style="text-align:center;">
';

$row_header .= $c;

$row_header .= '
</table>';

echo $row_header;
require_once('simple_html_dom.php');
$file='1http://testwork.ru/Tempp/domains.php'; // 带表格的页面
$SymbolsCountMin=0;
$SymbolsCountMax=10;
$SymbolsBackLis=数组('-'、'''u'、'.'0'、'1'、'2'、'3'、'4'、'5'、'6'、'7'、'8'、'9');
$ArrTr=array();
$ArrTd=array();
$ch=curl\u init($file);
curl_setopt($ch,CURLOPT_URL,$file);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_VERBOSE,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,数组(
'内容类型:application/x-www-form-urlencoded'
));
$html=curl\u exec($ch);
//$responseInfo=curl\u getinfo($ch);
卷曲关闭($ch);
//变量转储($html);
//$html=file\u get\u html('http://testwork.ru/Tempp/domains.php');
//查找所有tr
$row=0;
foreach($html->find('tr')作为$tr){
如果($row!=0){
$row++;
$column=0;
foreach($tr->find('td')作为$td){
$column++;
$text=$td->纯文本;
$ArrTd[$column]=$text;
}
}
if(iconv_strlen($ArrTd[0])>$SymbolsCountMin和&iconv_strlen($ArrTd[0])<$SymbolsCountMax和!in_数组($ArrTd[0],$SymbolsBackList)){
$ArrTr[$row]=$ArrTd;
}
}
$c='';
foreach($ArrTr as$arr_tr=>$ftr){
$c.='';
foreach($ftr为$arr\U td=>$ftd){
$c.='';
$c.=$ftd;
$c.='';
}
$c.='';
}
$row_页眉
';
$row_标题=$c;
$row_标题。='
';
echo$行标题;
我得到错误
致命错误:在第34行的/var/www/seo main/data/www/testwork.ru/Tempp/parse_domains.php中对非对象调用成员函数find()

请告诉我为什么出错以及如何纠正?

find()

你已经把这行注释掉了

$html = file_get_html('http://testwork.ru/Tempp/domains.php');
使用
CURL
它将返回html内容,而不是解析数据

如果您打算使用CURL,请使用

$html_data = curl_exec($ch);
curl_close ($ch);
$html = str_get_html($html_data ); // using the returned html from curl to the parser

然后执行解析部分的其余部分。

您需要像这样编辑代码:

// Find all tr 
$row = 0;
if(!$html) { // check if $html does exists
foreach($html->find('tr') as $tr){
    if($row!=0){
        $row++;
        $column = 0;
        foreach($tr->find('td') as $td){
            $column++;
            $text = $td->plaintext;

            $ArrTd[$column] = $text;
        }
    }
    if(iconv_strlen($ArrTd[0]) > $SymbolsCountMin && iconv_strlen($ArrTd[0]) < $SymbolsCountMax && !in_array($ArrTd[0], $SymbolsBackList)){
        $ArrTr[$row] = $ArrTd;
    }
}
}
//查找所有tr
$row=0;
如果(!$html){//检查$html是否存在
foreach($html->find('tr')作为$tr){
如果($row!=0){
$row++;
$column=0;
foreach($tr->find('td')作为$td){
$column++;
$text=$td->纯文本;
$ArrTd[$column]=$text;
}
}
if(iconv_strlen($ArrTd[0])>$SymbolsCountMin和&iconv_strlen($ArrTd[0])<$SymbolsCountMax和!in_数组($ArrTd[0],$SymbolsBackList)){
$ArrTr[$row]=$ArrTd;
}
}
}

或者使用try-and-catch语句

可能是您的
$html
为空,或者
为空,请在使用之前检查它是否为空。请告诉我
文件\u get\u html()
参数
允许url\u fopen
应该打开吗?当我设置“$html\u data=curl\u exec($ch)”;卷曲关闭($ch)$html=str_get_html($html_数据);`我也有这个错误。full vesion新代码和no u不应出现该错误。您正在使用CURL获取html,然后在这里加载返回的数据检查`var\u dump($html\u data)`show table in array,但是
find()
仍然存在问题。。我在示例上显示时会出错,但我也会出错。。。托管可能会有问题……您需要确保dom解析器可用于托管。