Home  >  Article  >  Backend Development  >  How to intercept a string between specified 2 characters in php

How to intercept a string between specified 2 characters in php

高洛峰
高洛峰Original
2017-01-03 15:18:592794browse

The example in this article describes how PHP intercepts a string between two specified characters. Share it with everyone for your reference. The details are as follows:

In PHP, you only need to determine the stripos position before string 1 and string 2 and then use substr to start intercepting. Here is a simple example.

Usage:

$keyword='查找(计组实验)'
$need=getNeedBetween($keyword, '(' , ')' );


After running the program:

$need='计组实验';


Let’s complete the string interception function getNeedBetween used above. This function can simply intercept the string between two specified characters ($mark1, $mark2) from the string ($kw). If it fails, it returns 0, and if it succeeds, it returns the intercepted string.

=$ed)
return 0;
$kw=substr($kw,($st+1),($ed-$st-1));
return $kw;
}
?>


I hope this article will be helpful to everyone’s PHP programming design.

For more related articles on how ob_start and other functions in PHP intercept standard output, please pay attention to the PHP Chinese website!

Statement:
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