These four functions in PHP are often confusing, and here are some notes to take.
1, Strstr
strstr-displays the string that was found for the first time, to find, and subsequent strings. Case sensitive.
Code Listing:
[PHP]
strstr function
$email = ' liruxing1715@sina.com@qq.com ';
$domain = Strstr ($email, ' @ ');
echo "strstr test result: {$domain}
";
$domain = Strstr ($email, ' @ ', true);
echo "strstr test result: {$domain}
";
/*
The test results are:
STRSTR test Result: @sina. com@qq.com
STRSTR test Result: liruxing1715
*/
strstr function
$email = ' liruxing1715@sina.com@qq.com ';
$domain = Strstr ($email, ' @ ');
echo "strstr test result: {$domain}
";
$domain = Strstr ($email, ' @ ', true);
echo "strstr test result: {$domain}
";
/*
The test results are:
STRSTR test Result: @sina. com@qq.com
STRSTR test Result: liruxing1715
*/NOTE: Returns FALSE if the string you are looking for is not found.
2, Stristr
The stristr-function is the same as the STRSTR function, and the only difference is the sense of capitalization.
3, STRRCHR
The strrchr-displays the string that was last found, to find, and subsequent strings.
Code Listing:
[PHP]
STRRCHR function
$email = ' liruxing1715@sina.com@qq.com ';
$domain = STRRCHR ($email, ' @ ');
echo "STRRCHR test result: {$domain}
";
/*
The test results are:
STRRCHR test Result: @qq. com
*/
STRRCHR function
$email = ' liruxing1715@sina.com@qq.com ';
$domain = STRRCHR ($email, ' @ ');
echo "STRRCHR test result: {$domain}
";
/*
The test results are:
STRRCHR test Result: @qq. com
*/NOTE: Returns FALSE if the string you are looking for is not found.
4, substr
substr-in a string, the character is intercepted according to the given length.
Format: String substr (string $string, int $start [, int $length])
Parameter description:
$string: the string to intercept;
$start: The starting position to intercept is starting at 0, and if start is a negative number, the returned string starts at the end of the $string at the beginning of the first $start character, or FALSE if the length of the string is less than or equal to start.
$length: The end position of the intercept, if the first $length is empty, then return from the start position to the end.
Code Listing:
[PHP]
substr function
$email = ' liruxing1715@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 digit of the string is-1
echo "substr test result: {$domain}
";
/*
The test results are:
SUBSTR test Result: 15@sina.com@qq.com
SUBSTR test Result: 15@si
SUBSTR test Result: q.com
*/
substr function
$email = ' liruxing1715@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 digit of the string is-1
echo "substr test result: {$domain}
";
/*
The test results are:
SUBSTR test Result: 15@sina.com@qq.com
SUBSTR test Result: 15@si
SUBSTR test Result: q.com
*/
http://www.bkjia.com/PHPjc/477898.html www.bkjia.com true http://www.bkjia.com/PHPjc/477898.html techarticle these four functions in PHP are often confusing, and here are some notes to take. 1. Strstr Strstr shows the first found, the string to find, and the following string. Case sensitive. to be a substitute for ...