【发布时间】:2020-11-24 08:42:47
【问题描述】:
我的 PHP 版本是 5.6.40。 我有一个变量,我想在其中存储一个图像 url。
$imageurl = "http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg";
我正在使用file_get_contents 函数来获取这张图片。
$contents = file_get_contents($imageurl);
但它不起作用,它显示空结果。但是当我尝试直接加载图片网址时,它起作用了。
$contents = file_get_contents("http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg");
怎么了?请帮忙。
谢谢
【问题讨论】:
-
不可重现,正如预期的那样,我得到了相同的结果。
-
@CBroe 奇怪,第二种方法对我有用,但我当然需要使用变量。
-
确保您的变量包含完全您认为应该包含的内容,对其进行 var_dump,并查看报告的字符串长度。确保其两侧没有额外的空格或其他不可打印的字符。
-
@CBroe 你是对的,我使用了 var_dump 并且看到长度不同。经过多次检查,我发现变量是十六进制代码 http://i132.photobucket.com/albums/q13/animalhelper2006/1376.jpg 最后我使用了 html_entity_decode 函数,它现在工作正常。非常感谢。
标签: php file-get-contents