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

Source: Internet
Author: User

PHP intercepts a method that specifies a string between 2 characters


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:

1

2

$keyword = ' Find (group experiment) '

$need =getneedbetween ($keyword, ' (', ') ');

After running the program:

1

$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.

1

2

3

4

5

6

7

8

9

10

11

12

function 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;

}

?>

http://www.bkjia.com/PHPjc/984499.html www.bkjia.com true http://www.bkjia.com/PHPjc/984499.html techarticle PHP intercepts the method of specifying a string between 2 characters in PHP as long as you judge the string 1 and the string 2 before the Stripos position and then use SUBSTR to start intercepting it, here to the big ...

  • 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.