首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >file_get_html在活动服务器中返回null,但在本地主机中工作良好。

file_get_html在活动服务器中返回null,但在本地主机中工作良好。
EN

Stack Overflow用户
提问于 2015-12-03 05:23:50
回答 1查看 730关注 0票数 1

我使用下面的代码来报废一个网页,它在本地主机上正常工作,但是返回

代码语言:javascript
复制
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,导致这种奇怪行为在本地主机上正常工作,但在活动服务器页面链接中工作正常。

EN

回答 1

Stack Overflow用户

发布于 2015-12-03 05:31:04

您必须将"allow_url_fopen“设置为"php.ini”中的TRUE,以允许通过HTTP或FTP访问文件。一些宿主供应商禁用PHP的"allow_url_fopen“标志以解决安全问题。

或者跟随帖子:html不起作用-有什么解决办法吗?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34058451

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档