Today’s article shares with you the method of intercepting a string between two specified characters in PHP. Friends in need can refer to it.
<?php 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; } ?>
$keyword='查找(计组实验)' $need=getNeedBetween($keyword, '(' , ')' );
Result:
$need='计组实验';
Related recommendations:
php intercept string function sharing, php intercept string
php method to intercept a string between specified 2 characters, intercept the string
The above is the detailed content of How to get string between 2 characters in PHP. For more information, please follow other related articles on the PHP Chinese website!