这款函数比较实用于数据采集,一般采集数据时会要指定一个区域的内容,这个代码就可以实例:
- $str=<!-- fdaf-- -->;
- echo strip_comments( $str );
- function strip_comments($data) {
- $the_rest = $data;
- $result = ;
- while ($the_rest) {
- $start = strpos($the_rest, <!--);
- if ($start === false) {
- $result .= $the_rest;
- break;
- }
- $result .= substr($the_rest, 0, $start);
- $end = strpos($the_rest, -->, $start);
- if ($end === false) {
- break;
- }
- $the_rest = substr($the_rest, $end+3);
- }
- return $result;
- }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。