Four confusing php text functions: strstrstrrchrsubstrstristr. In php, these four functions are often confusing. take notes here. 1. strstrstrstr: the string to be searched and the subsequent string. Case sensitive. These four functions are often confusing in php, so take notes here.
1. strstr
Strstr-displays the string to be searched and the subsequent string found for the first time. Case sensitive.
Code list:
[Php]
// 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
*/
// 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. stristr
The stristr-function is the same as the strstr function. The only difference is that the case sensitivity is unknown.
3. strrchr
Strrchr-display the last found string and the subsequent string.
Code list:
[Php]
// Strrchr function
$ Email = 'ruxing1715 @ sina.com@qq.com ';
$ Domain = strrchr ($ email ,'@');
Echo "strrchr test result: {$ domain}
";
/*
Test results:
Strrchr test result: @ qq.com
*/
// 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. substr
Substr-in a string, the string is truncated based on the given length.
Format: string substr (string $ string, int $ start [, int $ length])
Parameter introduction:
$ String: the string to be truncated;
$ Start: the start position to be intercepted. the default value is from 0. if start is a negative number, the returned string starts from the $ start character at the end of $ string; if the string length is less than or equal to start, FALSE is returned.
$ 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.
Code list:
[Php]
// 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
*/
// 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
*/
The four functions in the http://www.bkjia.com/PHPjc/477898.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477898.htmlTechArticlephp are often confusing and take notes here. 1. strstr: the string to be searched and the subsequent string. Case sensitive. Generation...