用preg_match获取网页中body部份内容/<body(.*?)>(.*?)<\/body>/is在PHP中用这个正帽,为什么匹配不了网页中body部份的内容?
比如163.com的。

解决方案 »

  1.   


    <?php
    $html = file_get_contents('http://news.163.com/');
    preg_match('/<body[^>]*>(.*)<\/body>/is',$html,$r);
    var_dump($r[0]); 
    ?>
      

  2.   


    好像可以了谢谢了。不懂这里为什么要用 [^>]*>像我之前那样。<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    把 bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> p这些都弄出来了。晕