我可以使用类似这样的方法来检索域外部的页面吗?
<?php
$q_pass =$_REQUEST['query_passed'];
$fetcher = "http://www.abc.com/search?q=".$q_pass;
$homepage = file_get_contents($fetcher);
echo $homepage;
?>
我传递了一个变量并想从 abc.com 检索结果。是否可以将 $fetcher 传递给 file_get_contents 以检索页面内容?当我点击这个 php 页面时,我得到了空白页面。但是如果我使用类似
的东西,它又可以正常工作了 <?php
$fetcher = "http://www.abc.com/search?q=query";
$homepage = file_get_contents($fetcher);
echo $homepage;
?>
这里发生了什么?对此有一些技术解释吗?
最佳答案
您应该在 $q_pass 上使用 urlencode。我猜你在 query_passed 中传递了一个带有空格的值。
关于php - 以 url 作为变量的 file_get_contents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4672597/