【发布时间】:2016-05-26 21:45:51
【问题描述】:
我正在尝试为我正在制作的网站添加一个基本的 new-grabber,但我终其一生都无法弄清楚导致此错误的原因。我抓取的文件是纯文本文件,完全可以访问。
我之前看过它发布过,并且 OP 正在调用类似的内容:
$var = $data[str] 而不是 $var = $data['src']
但我并没有在名称中调用任何带有“代码”的东西。 我在运行代码时收到此错误:
HTTP 请求失败。第 123 行的错误 8:使用未定义的常量 代码 - 假定文件 /usr/local/lib/php/head.php 中的“代码”
下面是我的整个文件:
<?
$e_news = file_get_contents("http://cinemattson.com/templates/flickfeed/news.txt");
if (!$e_news === true) {
$error = error_get_last();
echo "HTTP request failed. Error " . $error['type'] . " on line " . $error['line'] . ": " . $error['message'] . " in file " . $error['file'] . "<br>";
} else {
echo "Everything went better than expected";
}
if ($e_news === true) {
$news = explode("|", $e_news);?>
<h4>News - <? echo (!empty($news) ? $news[1] : "v0.0.1");?> <small><? echo (!empty($news) ? $news[0] : "5/22/2016");?></small></h4>
<p><? echo (!empty($news) ? $news[2] : "Loading news failed, or there is currently no news.");?></p>
<?
} else {
echo "<h4>News failed to load</h4>";
}
?>
你们知道我在这里遗漏了什么或做错了什么吗?
【问题讨论】:
-
问题在别处。
-
还有一行和一个文件。你确定它们就是你给我们看的吗?
-
执行
print_r(error_get_last());找出导致它的文件和行号。 -
警告 file_get_contents() 可能返回布尔值 FALSE,但也可能返回非布尔值,其计算结果为 FALSE。请阅读有关布尔值的部分以获取更多信息。使用 === 运算符测试此函数的返回值。 - php.net/file_get_contents
-
我猜这是我的主机 000webhost 的问题,但我在另一个文件中对 vimeo.com 进行了类似的调用,这很好。
标签: php httprequest file-get-contents