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