<?php
  $baidu="http://www.baidu.com/s?wd=site%3Ahao123.com";
  $site=file_get_contents($baidu);
  $site= iconv("UTF-8","GB2312", $site);
  ereg("<title>(.*)</title>", $site,$count);
print_r($count); //获取好主题在百度中的收录数量?>
这个能获得结果:Array ( [0] => [1] => 百度搜索_site:hao123.com )
但是:<?php
  $baidu="http://www.baidu.com/s?wd=site%3Ahao123.com";
  $site=file_get_contents($baidu);
  $site= iconv("UTF-8","GB2312", $site);
  ereg("<strong>(.*)</strong>", $site,$count);
print_r($count); //获取好主题在百度中的收录数量?>
这个就不行了
求解释,还有怎么获得百度收录量。

解决方案 »

  1.   


    preg_match('%<strong>找到相关结果数(.*?)个。</strong>%i', $site,$count);
      

  2.   

    %<strong>找到相关结果数(.*?)个。</strong>%i关键是最后的那个“i”表示忽略大小写,如果不加“i”也就不需要“%”了
      

  3.   


    正则里面的"."匹配除"\n"外的任意一个字符,不能匹配中文。
    preg_match('%<strong>找到相关结果数(.*?)个。</strong>%i', $site,$count);
    和下面的一样:
    preg_match('/<strong>找到相关结果数(.*?)个。</strong>/i', $site,$count);
      

  4.   

    其实这种
    preg_match('/<strong>找到相关结果数(.*)个。<\/strong>/i',$site,$count);
    就可以了。