我使用下面的代码来报废一个网页,它在本地主机上正常工作,但是返回
require_once('advanced_html_dom.php');
$dom = file_get_html('http://exams.keralauniversity.ac.in/Login/index.php?reslt=1');
$rows = array();
foreach($dom->find('tr.Function_Text_Normal:has(td[3])') as $tr){
$row['num'] = $tr->find('td[2]', 0)->text;
$row['text'] = $tr->find('td[3]', 0)->text;
$row['pdf'] = $tr->find('td[3] a', 0)->href;
if(preg_match_all('/\d+/', $tr->parent->find('u', 0)->text, $m)){
list($row['day'], $row['month'], $row['year']) = $m[0];
}
// uncomment next 2 lines to save the pdf
// $filename = preg_replace('/.*\//', '', $row['pdf']);
// file_put_contents($filename, file_get_contents($row['pdf']));
$rows[] = $row;
}
var_dump($rows);当我进一步检查时,它显示了以下错误
“警告:为第477行的/home/a 7944217/public_html/Resul.php中的foreach()提供的无效参数”
var_dump --这一行$dom->find('tr.Function_Text_Normal:has(td[3])')和$dom在转储时返回空对象,显示此对象(AdvancedHtmlDom)#1 (6) { ["xpath"]=> NULL ["root"]=> NULL ["doc"]=> RECURSION ["dom"]=> NULL ["node"]=> NULL ["is_text"]=> bool(false) }
file_get_html返回空.whats,导致这种奇怪行为在本地主机上正常工作,但在活动服务器页面链接中工作正常。
发布于 2015-12-03 05:31:04
您必须将"allow_url_fopen“设置为"php.ini”中的TRUE,以允许通过HTTP或FTP访问文件。一些宿主供应商禁用PHP的"allow_url_fopen“标志以解决安全问题。
或者跟随帖子:html不起作用-有什么解决办法吗?
https://stackoverflow.com/questions/34058451
复制相似问题