微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php获取指定位置内容

这款函数比较实用于数据采集,一般采集数据时会要指定一个区域的内容,这个代码就可以实例:

  1. $str=<!-- fdaf-- -->
  2. echo strip_comments( $str ); 
  3.  
  4. function strip_comments($data) { 
  5.     $the_rest = $data
  6.     $result = 
  7.  
  8.     while ($the_rest) { 
  9.         $start = strpos($the_rest<!--); 
  10.         if ($start === false) { 
  11.             $result .= $the_rest
  12.             break
  13.         } 
  14.  
  15.         $result .= substr($the_rest, 0, $start); 
  16.  
  17.         $end = strpos($the_rest-->$start); 
  18.         if ($end === false) { 
  19.             break
  20.         } 
  21.  
  22.         $the_rest = substr($the_rest$end+3); 
  23.     } 
  24.  
  25.     return $result

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐