浏览文章

文章信息

PHP截取指定两个字符之间的字符串|How to cut string betwen two special char 17882

1、欢迎新的方法

   /**
     * 截取指定两个字符之间的字符串,一个返回截取部分,多个返回数组
     * @param string $start_fix
     * @param string $end_fix
     * @param $str
     * @return array
     */
    public function strCut($string, $start_fix = '{', $end_fix = '}')
    {
        $have_start_fix = true;
        $str_fix = array();
        while ($have_start_fix) {
            $start_fix_str = strstr($string, $start_fix);
            $have_start_fix = $start_fix_str ? true : false;
            if (strpos($start_fix_str, $end_fix)) {
                $cut = substr($start_fix_str, 1, strpos($start_fix_str, $end_fix)-1);
                $fix_cut = $start_fix . $cut . $end_fix;
                $str_fix[$cut] = $fix_cut;
                $string = str_replace($fix_cut,'',$start_fix_str);
            }
        }
        return $str_fix;
    }


原创