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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...