PHP strstr, STRRCHR, substr, stristr Four functional usage differences:
PHP strstr STRRCHR substr stristr These four string manipulation functions are especially confusing, often substr,strstr, which can basically satisfy the operation of the string.
Here are some of the different functions.
I. The difference between STRSTR and STRCCHR
STRSTR Displays the first found, the string to look for, and the string that follows.
STRRCHR displays the last found, the string to look for, and the string to follow.
Copy Code code as follows:
<?php
$email = ' test@test.com@jb51.net ';
$domain = Strstr ($email, ' @ ');
echo "STRSTR test results $domain <br>";
$domain = STRRCHR ($email, ' @ ');
echo "STRRCHR test results $domain <br>";
?>
The results are as follows:
STRSTR test results @test. com@jb51.net
STRRCHR test results @jb51. Net
Ii. the difference between strstr and STRISTR
Strstr is case sensitive.
STRISTR is not case sensitive.
Copy Code code as follows:
<?php
$email = ' zhangYing@jb51.net ';
$domain = Strstr ($email, ' Y ');
echo "STRSTR test results $domain <br>";
$domain = Stristr ($email, ' Y ');
echo "STRISTR test results $domain <br>";
?>
The results are as follows:
STRSTR Test Results Jb51.net
STRISTR Test Results Ying@jb51.net
Iii. the difference between strstr and substr
STRSR is matched after interception.
The substr is not matched and is intercepted according to the starting position.
Copy Code code as follows:
<?php
$email = ' zhangYing@jb51.net ';
$domain = Strstr ($email, ' Y ');
echo "STRSTR test results $domain <br>";
$domain = substr ($email,-7);
echo "substr test results $domain <br>";
?>
The results are as follows:
STRSTR Test Results Jb51.net
SUBSTR Test Results Jb51.net
Make sense of this several string intercept functions, you can save a lot of things when developing