PHP简单获取网站百度搜索方法

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是根据网上方法改进

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_708.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?