How to intercept the string between specified 2 characters in php
In php, you only need to determine the stripos position before string 1 and string 2 and then use substr to start intercepting That’s it, here’s a simple example for you.
Usage:
1
2
|
$keyword='查找(计组实验)'
$need=getNeedBetween($keyword, '(' , ')' );
|
1
2
|
$keyword='Search (group experiment)'
$need=getNeedBetween($keyword, '(' , ')' );
|
After running the program:
1
2
3
4
5
6
7
8
9
10
11
12
|
function getNeedBetween($kw1,$mark1,$mark2){
$kw=$kw1;
$kw='123′.$kw.'123′;
$st =stripos($kw,$mark1);
$ed =stripos($kw,$mark2);
if(($st==false||$ed==false)||$st>=$ed)
return 0;
$kw=substr($kw,($st 1),($ed-$st-1));
return $kw;
}
?>
|
1
|
$need='Group experiment';
|
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.
1
2
3
4
56
7
8
9
10
11
12
|
<🎜>function getNeedBetween($kw1,$mark1,$mark2){<🎜>
<🎜>$kw=$kw1;<🎜>
<🎜>$kw='123′.$kw.'123′;<🎜>
<🎜>$st =stripos($kw,$mark1);<🎜>
<🎜>$ed =stripos($kw,$mark2);<🎜>
<🎜>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.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/984499.htmlTechArticlephp method to intercept the string between specified 2 characters. In php, just judge string 1 and string 2 Just use the previous stripos position and then use substr to start intercepting it. Here is the big one...