substr()
substr() function is used to get a part of a string and return a string.
Syntax:
string substr ( string string, int start [, int length] )
Parameter description is as follows:
Example:
$str_bh='123456789';$abc=substr($str_bh,-4); echo $abc;
Output:
6789
<?php echo substr("Hello world!",6,5); ?>
Output:
world
<?php echo substr('abcdef', 1); ?>
Output:
bcdef
Related recommendations: "php Basic Tutorial"
strstr()
Find the first occurrence of a string in another string and return all characters from that position to the end of the string. If not found, return FALSE.
Syntax:
string strstr ( string string, string needle )
Parameter description is as follows:
Example:
<?php $email = 'user@5idev.com'; $domain = strstr($email, '@'); echo $domain; ?>
Output:
@5idev.com
strrchr()
#Find the last occurrence of a string in another string and return from that position to the end of the string All characters, if not found, returns FALSE.
Syntax:
string strrchr ( string string, string needle )
This function behaves the same as the strstr() function. For the meaning of the parameters, please refer to the strstr() function parameter description above.
Example:
<?php $str="AAA|BBB|CCC"; echo strrchr($str, "|"); ?>
Output:
|CCC
The above is the detailed content of How to intercept the last few digits of a string in php. For more information, please follow other related articles on the PHP Chinese website!