Php intercepts a string between two characters. Php intercepts a string between two characters. in php, you only need to determine a stripos location before String 1 and string 2, and then use substr to start intercepting, here is a method for intercepting strings between two characters for php.
In php, you only need to determine a stripos location before String 1 and string 2, and then use substr to start the truncation. here is a simple example.
Usage:
|
1
2 |
$ Keyword = 'Search (group experiment )'
$ Need = getNeedBetween ($ keyword ,'(',')');
|
After running the program:
The following describes how to use the string truncation function getNeedBetween. This function allows you to extract strings between two specified characters ($ mark1, $ mark2) from the string ($ kw). If the string fails, 0 is returned, and the string is successfully returned.
|
1
2
3
4
5
6
7
8
9
10
11
12 |
Function getNeedBetween ($ kw1, $ mark1, $ mark2 ){
$ Kw = $ kw1;
$ Kw = '000000'. $ kw. '000000 ′;
$ 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;
}
?>
|
In php, you only need to determine a stripos location before String 1 and string 2, and then use substr to start intercepting the string. here we will give it a large value...