PHP collection tool: truncate required content data based on the start string and end string _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP collection tool: captures the required content data based on the start string and end string. PHP collection tool: Collect required data based on the start string and end string. PHP collection tool: Collect required data based on the start string and end string. PHP collection tool: truncate the required content data based on the start string and end string

PHP collection tool: captures the required 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);    }

Example:

$ Str = '1 that is a game 23 I ask 4567890 '; echo (strCutByStr ($ str,' that is ', 'stair ')); // output a field 23. I will ask 4567890 dimensions.


Tips for collecting PHP Data: extract the required content data based on the start string and end string...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.