当前位置: 动力学知识库 > 问答 > 编程问答 >

php - file_get_contents with url as variable

问题描述:

Can I use something like this to retrieve the page that is external with respect to the domain.

<?php

$q_pass =$_REQUEST['query_passed'];

$fetcher = "http://www.abc.com/search?q=".$q_pass;

$homepage = file_get_contents($fetcher);

echo $homepage;

?>

I have passed a variable and want to retrieve the result from the abc.com. Can $fetcher can be passed over to file_get_contents to retrieve the contents of the page? I am getting blank page when I hit this php page. But its again working fine if I use something like

 <?php

$fetcher = "http://www.abc.com/search?q=query";

$homepage = file_get_contents($fetcher);

echo $homepage;

?>

What is happening here? Is there some technical explanation for this?

网友答案:

You should use urlencode on $q_pass. I'm guessing your passing a value with spaces in it in query_passed.

分享给朋友:
您可能感兴趣的文章:
随机阅读: