function baidu($url){ $baidu="http://www.baidu.com/s?wd=site:".$url; $site=file_get_contents($baidu); //var_dump($site); 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 baidu2($url){ $baidu="http://www.baidu.com/s?wd=site:".$url; $site=file_get_contents($baidu); $site = preg_replace('/\s+/', '', $site); //var_dump($site); $str = '/该网站共有(.*?)个网页被百度收录/'; preg_match($str, $site,$count); return $count[1]; //$count=str_replace("该网站共有","",$count); //$count=str_replace("个网页被百度收录","",$count); //$count=str_replace(",","",$count); //$count=str_replace(" ","",$count); //var_dump($count); //return strip_tags($count[0]); }
百度收录<?php echo baidu2(‘www.jb51.net’);?>条
方法2是根据网上方法改进