本文實例講述了PHP簡單獲取網站百度搜索和搜狗搜索收錄量的方法。分享給大家供大家參考,具體如下:
獲取網站百度搜索和搜狗搜索的收錄量代碼,可以用于獲取網站域名在搜索引擎的收錄數量,一直想找這個API但沒找到,就在網上找了個例子,學習修改了下,可以正常獲取百度搜索和搜狗搜索的收錄量了;原理是獲取搜索引擎site:domain的結果數量,然后再抓取這個數量顯示出來。
function baidu($url){ $baidu="http://www.baidu.com/s?wd=site:".$url; $site=file_get_contents($baidu); ereg("該網站共有(.*)個網頁被百度收錄", $site,$count); $count=str_replace("該網站共有","",$count); $count=str_replace("個網頁被百度收錄","",$count); $count=str_replace(",","",$count); $count=str_replace(" ","",$count); return strip_tags($count[0]); } function sogou($url){ $sogou="http://www.sogou.com/web?query=site:".$url; $site=file_get_contents($sogou); ereg("找到約 (.*) 條結果", $site,$count); $count=str_replace("找到約","",$count); $count=str_replace("條結果","",$count); $count=str_replace(",","",$count); $count=str_replace(" ","",$count); return strip_tags($count[0]); } ?> m.ythuaji.com.cn 百度收錄<?php echo baidu('m.ythuaji.com.cn');?>條<br> m.ythuaji.com.cn 搜狗收錄<?php echo sogou('m.ythuaji.com.cn');?>條
注意:此處的文件編碼需要使用utf-8格式。
希望本文所述對大家PHP程序設計有所幫助。