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.