Home >Backend Development >PHP Tutorial >A PHP class that intercepts strings between specified strings

A PHP class that intercepts strings between specified strings

巴扎黑
巴扎黑Original
2016-11-24 14:45:181383browse

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(&#39;[123456789]&#39;,&#39;[&#39;,&#39;]&#39;);
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn