Home > Backend Development > PHP Tutorial > PHP collection tool: intercept the required collection content data based on the start string and end string_PHP tutorial

PHP collection tool: intercept the required collection content data based on the start string and end string_PHP tutorial

WBOY
Release: 2016-07-13 10:13:36
Original
969 people have browsed it

PHP collection tool: intercept the required collection content data based on the start string and end string

PHP collection tool: intercept the required collection content data based on the start string and end string

function strCutByStr(&$str, $findStart, $findEnd = false, $encoding = 'utf-8'){
        if(is_array($findStart)){
            if(count($findStart) === count($findEnd)){
                foreach($findStart as $k => $v){
                    if(($result = strCutByStr($str, $v, $findEnd[$k], $encoding)) !== false){
                        return $result;
                    }
                }
                return false;
            }else{
                return false;
            }
        }
         
        if(($start = mb_strpos($str, $findStart, 0, $encoding)) === false){
            return false;
        }
         
        $start += mb_strlen($findStart, $encoding);
         
        if($findEnd === false){
            return mb_substr($str, $start, NULL, $encoding);
        }
         
        if(($length = mb_strpos($str, $findEnd, $start, $encoding)) === false){
            return false;
        }
         
        return mb_substr($str, $start, $length - $start, $encoding);
    }
Copy after login

Example:

$str = '1那是一场23我问问4567890维稳';

echo (strCutByStr($str, '那是', '稳'));//输出 一场23我问问4567890维
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/914775.htmlTechArticlePHP collection tool: intercept the required collection content data based on the start string and end string PHP collection tool: based on the start string Collection content data required for string and end string interception...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template