首页  >  文章  >  后端开发  >  一个php截取指定字符串其间的字符串的类

一个php截取指定字符串其间的字符串的类

WBOY
WBOY原创
2016-06-13 13:07:59811浏览

一个php截取指定字符串之间的字符串的类

?

class get_c_str {
var $str;
var $start_str;
var $end_str;
var $start_pos;
var $end_pos;
var $c_str_l;
var $contents;
function get_str($str,$start_str,$end_str){
   $this->str = $str;
   $this->start_str = $start_str;
   $this->end_str = $end_str;
   $this->start_pos = strpos($this->str,$this->start_str)+strlen($this->start_str);
     $this->end_pos = strpos($this->str,$this->end_str);
   $this->c_str_l = $this->end_pos - $this->start_pos;
   $this->contents = substr($this->str,$this->start_pos,$this->c_str_l);
   return $this->contents;
}
}?>
<?php
$get_c_str = new get_c_str;
echo $get_c_str -> get_str('[123456789]','[',']');
?> 
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn