<?php
//$searchterm = "acer predator 21x";
//$searchres = urlencode($searchterm);
$reffer = "https://www.google.com/";
$LOGINURL = "https://www.google.com/search?site=&source=hp&q=acer+predator+21x&oq=acer+predator+21x&gs_l=psy-ab.3...116308.122177.0.126746.0.0.0.0.0.0.0.0..0.0....0...1.1.64.psy-ab..0.0.0.jZC5TmHjRnI
";
$agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
$result = curl_exec ($ch);
if(curl_error($ch)) {
echo "error ".curl_errno($ch)."<br / >";
echo "error ".curl_error($ch);
}
curl_close ($ch);
echo $result;
?>
我使用php curl搜索谷歌并收到此错误&#34;错误3 错误在URL&#34;中找到非法字符,我试图在堆栈上搜索的问题可能是什么,我找不到任何有用的答案。
答案 0 :(得分:-1)
从url动态替换\ n和额外空格,如此
{{1}}