file_get_html在实时服务器中返回null,但在localhost中运行良好


file_get_html returns null in live server but works fine in localhost

我使用以下代码废弃了一个网页,它在localhost上正常工作,但返回

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

当我进一步检查时,它显示了以下错误

"警告:中为foreach()提供的参数无效/home/a7944217/public_html/Results.php,第477行"

var_dump此行$dom->find('tr.Function_Text_Normal:has(td[3])')$dom在转储时返回null对象显示此对象(AdvancedHtmlDom)#1(6){ ["xpath"]=> NULL ["root"]=> NULL ["doc"]=> RECURSION ["dom"]=> NULL ["node"]=> NULL ["is_text"]=> bool(false) }

file_get_html返回null。导致这种奇怪行为的原因在localhost中正常工作,但在实时服务器页面链接中无效

必须在"php.ini"中将"allow_url_fopen"设置为TRUE,才能允许通过HTTP或FTP访问文件。一些主机供应商出于安全问题禁用了PHP的"allow_url_fopen"标志。

或者跟随帖子:简单的html dom file_get_html不起作用——有什么解决办法吗?

相关文章: