加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php获取指定位置内容

发布时间:2020-12-13 20:53:18 所属栏目:PHP教程 来源:网络整理
导读:这款函数比较实用于数据采集,一般采集数据时会要指定一个区域的内容,这个代码就可以实例: $str = !--fdaf---- ; echo strip_comments( $str ); function strip_comments( $data ){ $the_rest = $data ; $result = ; while ( $the_rest ){ $start = strpos (

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

  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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读