Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.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
PHP文件获取内容返回404_Php_File Get Contents - Fatal编程技术网

PHP文件获取内容返回404

PHP文件获取内容返回404,php,file-get-contents,Php,File Get Contents,我有一个很奇怪的问题。我从3个小时开始尝试从$ht输出。当我回显$ht时,结果是。没问题。但当我使用变量$ht执行file_get_内容时,就没有输出了。我已经试过了,旋度也没有输出-404 foreach ($hashtweet[1] as $ht) { $html = file_get_contents($ht); //NOT WORKING $html = file_get_contents("http://www.google.com"); // WORKING ech

我有一个很奇怪的问题。我从3个小时开始尝试从$ht输出。当我回显$ht时,结果是。没问题。但当我使用变量$ht执行file_get_内容时,就没有输出了。我已经试过了,旋度也没有输出-404

foreach ($hashtweet[1] as $ht)
        {

$html = file_get_contents($ht); //NOT WORKING
$html = file_get_contents("http://www.google.com"); // WORKING
echo $html;

//echo $ht;  = CORRECT OUT OF $ht = http://www.google.com

        }       

您应该使用修剪功能:

$html = file_get_contents(trim($ht)); 
可能某些空格或其他白色字符位于字符串的开头或结尾

编辑

在您的问题中,您告诉我们,
$ht
http://www.google.com
但在你告诉我的评论中,它是
google.com
。如果您想获得
http://google.com
您需要添加
http://
。否则,这意味着您需要在当前目录文件中使用名称
google.com

EDIT2

所以你应该比较这两个字符串。在循环中添加:

if (trim($ht) == 'http://www.google.com') {
  echo "same strings<br />";
}
else {
  echo "there is difference<br />";
}
if(修剪($ht)='http://www.google.com') {
回显“相同字符串
”; } 否则{ 回声“存在差异
”; }

以确保这些字符串是否相同。您告诉我您的$ht返回
字符串(21)”http://www.gooogle.com“
所以它不可能不工作,因为string
http://www.gooogle.com
字符串的长度正好为21个字符。在运行file\u get\u contents之前或在循环中运行之后,是否更改
$ht
变量?

无法帮助您查看
$hashTweet
。在
$ht
的值中必须有一些额外的字符。你应该做
var\u转储($ht)
以找出确切的内容。尝试将$ht打印为-echo(“\“$ht\”);嘿,var_dump的输出($ht);字符串(21)”,并且$html=file_get_contents(trim($ht));也不起作用…你能通过编辑在你的问题中输入准确的输出吗?因为
google.com
不是21个字符长;字符串(21)”,并且$html=file_get_contents(trim($ht));也不起作用…是用http://开始的,但是stackoverflow将其短接到google.com…http://www.google.com…21字符是http://www.google.com(没有空格)stackoverflow是缩短到google的链接。com@CubeBoy69请看编辑后的答案。但是,这两个字符串不可能不同,因为
http://www.google.com
也是21个字符。天哪-你看不懂吗?!我说如果没有空间,我就不能写http://www.google.com,因为stackoverflow被缩短为google.com