1. In the development process, the required string needs to be processed, specifically to obtain the character 191 of the string 'm-184-191', the code is as follows
$ spm = 'm-184-191'; $result = substr($spm,strripos($spm,"-")+1); echo $result;
2. In the development process, the required strings need to be processed, specifically to obtain the character 'admin/auth' of the string 'admin/auth/index', the code is as follows
$url = 'admin/auth/index'; $result = substr($url,0,strrpos($url,"/");
echo $result;
The above two pieces of code mainly use several functions: ① strrpos() function finds the last occurrence of a string in another string (case-sensitive);
② strripos - finds the position of the last occurrence of a string in another string (case-insensitive);
③ The substr() function returns part of the string.
The first piece of code to understand: find the last occurrence of '-' in the last string 'm-184-191' through strripos, then add one, and then intercept the string after the last '-' through substr (excluding the last A '-')
Understanding of the second piece of code: find the last occurrence of '/' through strrpos, and intercept the string from the beginning of the string 'admin/auth/index' to the position before the last '/' through string interception ( excluding the final '/')