错误 3 错误 在 URL 卷曲 PHP 中发现非法字符


<?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在谷歌上搜索,并收到此错误"错误3 错误在 URL 中发现非法字符",我试图在堆栈上搜索但找不到任何有用的答案可能是什么问题。

Sure iXCray

$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"; //no n anymore

那行得通!!

动态替换 和 url 中的额外空间,如下所示

<?php 
//$searchterm = "acer predator 21x";
//$searchres =  urlencode($searchterm);
$reffer = "https://www.google.com/";
$string = "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
";  
$LOGINURL = trim(preg_replace('/ss+/', ' ', $string));
$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;
?>

最新更新