- // Strstr function
- $ Email = 'ruxing1715 @ sina.com@qq.com ';
- $ Domain = strstr ($ email ,'@');
- Echo "strstr test result: {$ domain}
";
- $ Domain = strstr ($ email, '@', true );
- Echo "strstr test result: {$ domain}
";
- /*
- Test results:
- Strstr test result: @ sina.com@qq.com
- Strstr test result: liruxing1715
- */
- ?>
-
Note: If the string to be searched is not found, FALSE is returned.2. stristrThe stristr-function is the same as the strstr function. The only difference is that the case sensitivity is unknown. 3. strrchrStrrchr-display the last found string and the subsequent string.
- // Strrchr function
- $ Email = 'ruxing1715 @ sina.com@qq.com ';
- $ Domain = strrchr ($ email ,'@');
- Echo "strrchr test result: {$ domain}
";
- /*
- Test results:
- Strrchr test result: @ qq.com
- */
- ?>
-
Note: If the string to be searched is not found, FALSE is returned.4. substrSubstr-in a string, the string is truncated based on the given length. Format: string substr (string $ string, int $ start [, int $ length]) parameter description: $ string: string to be truncated; $ start: start position to be truncated, the default value is start from 0. if start is a negative number, the returned string starts with the $ start character at the end of $ string. if the string length is less than or equal to start, returns FALSE. $ Length: the end position of the truncation. if the value of $ length is null, the return value ranges from the start position to the end.
- // Substr function
- $ Email = 'ruxing1715 @ sina.com@qq.com ';
- $ Domain = substr ($ email, 10 );
- Echo "substr test result: {$ domain}
";
- $ Domain = substr ($ email, 10, 5 );
- Echo "substr test result: {$ domain}
";
- $ Domain = substr ($ email,-5, 5); // The last character of the string is-1.
- Echo "substr test result: {$ domain}
";
- /*
- Test results:
- Substr test results: 15@sina.com @ qq.com
- Substr test result: 15 @ si
- Substr test result: q.com
- */
- ?>
|