This article describes how to intercept a string between two characters in php and implement this function through a simple custom function, it mainly involves the use of stripos, substr, and other methods in php, and has some reference value. if you need it, you can refer to the example below to describe how php intercepts strings between two specified characters. Share it with you for your reference. The details are as follows:
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:
$ Keyword = 'Search (group experiment) '$ need = getNeedBetween ($ keyword ,'(',')');
After running the program:
$ Need = 'group lab ';
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.
<? Phpfunction 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 ;}?>
I hope this article will help you with php programming.