PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php 查询百度与google收录情况的实现代码

原创
2016-07-25 08:57:09 850浏览
本文介绍下,用php实现的查询百度收录、谷歌收录情况的一段代码,有需要的朋友参考下。

用php来查询百度或google的收录情况,其实并不复杂,只需要file下远程文件,然后分析相关数据即可。

以下是收录查询核心代码,getdetail函数也可以这样写,用正则去匹配:

$wordf = preg_quote($wordf);
$wordb = preg_quote($wordb);
$pagecontent = @preg_replace("/\s*$wordf(.+?)$wordb\s*/e", "returndetail('\\1', '$type')", $pagecontent);
$pagecontent = @preg_replace("/\s*".preg_quote($wordf)."(.+?)".preg_quote($wordb)."\s*/e", "returndetail('\\1', '$type')",
 $pagecontent);

完整代码:

 个结果,', ' 个。  (搜索用时');
getdetail($google_link, 'google_link', '约有 ', ' 项链接到 ');//102
}

function getdetail($url, $type, $wordf, $wordb) {
$pagecontent = @file($url);
$pagecontent = implode('', $pagecontent);
$pagecontent = substr(strstr($pagecontent, $wordf), strlen($wordf));
$pagecontent = substr_replace($pagecontent, '', strpos($pagecontent, $wordb));
returndetail($pagecontent,$type);
}

function returndetail($content,$type) {
global $seodetail;
$seodetail[$type] = empty($content) ? 0 : $content;
}
?>


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。