PHP intercepts a method that specifies a string between 2 characters _php

Source: Internet
Author: User
Keywords PHP Intercept string
This article describes a method by which PHP intercepts a string specified between 2 characters. Share to everyone for your reference. Specific as follows:

In PHP just judge the string 1 and the string 2 before the Stripos position and then use SUBSTR to start interception, here is a simple example.

How to use:

$keyword = ' Find (group experiment) ' $need =getneedbetween ($keyword, ' (', ') ');

After running the program:

$need = ' group experiment ';

The following is the completion of the above used string intercept function Getneedbetween. The function implements a simple string ($kw) to intercept two specified characters ($mark 1, $mark 2) between the strings, the failure returns 0, and the truncated string is successfully returned.

<?phpfunction Getneedbetween ($kw 1, $mark 1, $mark 2) {$kw = $kw 1; $kw = ' 123′ $kw. ' 123′; $st =stripos ($kw, $mark 1); $ed Stripos ($kw, $mark 2); if ($st ==false| | $ed ==false) | | $st >= $ed) return 0; $kw =substr ($kw, ($st + 1), ($ed-$st-1); return $kw;}? >

I hope this article is helpful to everyone's PHP programming.

  • Related Article

    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.