PHP - file_get_contents() 自动回显到 HTML 页面
我在远程服务器上有一个页面,其中包含以下行:
$contents = file_get_contents($search_url);
无论我做什么,它都会自动将 $contents 回显到 HTML 页面。就好像我做了以下事情:
$contents = file_get_contents($search_url);
echo $contents;
什么可能导致 PHP 这样做?是否有任何配置项需要更改?
I have a page on a remote server with the following line:
$contents = file_get_contents($search_url);
which automatically echoes $contents to the HTML page no matter what I do. It's as if I have done the following:
$contents = file_get_contents($search_url);
echo $contents;
What could be causing PHP to do this? Is there any configuration item that needs changing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能值得看一下您的这段代码。如果把它注释掉,还会出现同样的情况吗?
这似乎与您之前在
file_get_contents()
中获取的内容相呼应。It might be worth taking a look at this bit of your code. If you comment it out, does the same thing still happen?
This does appear to echo what you have previously fetched in the
file_get_contents()
.这是一个愚蠢的错误 - 变量 $contents 正在被包含的文件以及包含它的函数中使用。这导致了问题 - file_get_contents 没有任何问题!
It was a STUPID bug - the variable $contents is being used in the included file as well as in the function it is included from. This caused the issue - nothing wrong with file_get_contents!