How PHP intercepts a string between a specified two characters

Source: Internet
Author: User
This article is mainly to share with you how PHP intercepts the specified two-character string between the methods, I hope to help everyone.

/** * php intercept specifies a string between two characters, the default character set is Utf-8 Power by Big Ear Tutu * @param string $begin  Start String * @param string $end    End String * @param String $str    strings to intercept * @return string */function cut ($begin, $end, $str) {    $b = Mb_strpos ($str, $begin) + Mb_strlen ( $begin);    $e = Mb_strpos ($str, $end)-$b;    Return Mb_substr ($str, $b, $e);} Call echo $this->cut (' token/', '? code ', $REDIRECTURL);d ie;

The above method is not very good, when the intercept is the value of the string, there will be no interception of the situation with the following bar

/* * PHP intercept specifies two characters between strings * */function Get_between ($input, $start, $end) {    $substr = substr ($input, strlen ($start) +strpos ($input, $start), (strlen ($input)-Strpos ($input, $end)) * ( -1));    return $SUBSTR;} Call $svid = $this->get_between ($redirectUrl, "token/", "? Code=");

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.