用google检查网址,安全=有效

时间:2014-05-17 09:47:43

标签: php curl

如何查看是否谷歌显示网址?

示例:

https://www.google.com/search?q=redtubex.xxx&safe=active

代码:

$input = 'http://www.example.com';
$input = trim($input, '/');
if (!preg_match('#^http(s)?://#', $input))
{
     $input = 'http://' . $input;
}

$urlParts = parse_url($input);
$domain = preg_replace('/^www\./', '', $urlParts['host']);
$request = 'https://www.google.com/search?q='.$domain.'&safe=active/';

$ch = curl_init($request);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_exec($ch);
curl_close($ch);

preg_match_all('/<cite.*?>(.*?)<\/cite>/', $data, $matches); 
foreach ($matches as $fmatch)
{
    echo $fmatch[1]);
}

0 个答案:

没有答案