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=".$开发者_StackOverflow中文版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.
精彩评论