PHP functions for splitting strings
1,substr
$str 1=substr($str, 5);Echo"Start from the 5th character to the last:".$str 1.";$str 2= substr ($str, 9,4); Echo"Start with the 9th character and take 4 characters:".$str 2.";$STR 3=substr($str--t);Echo"Take the bottom 5 characters:".$STR 3.";$STR 4= substr ($str, -8,4); Echo"Start from the last 8th character and take 4 characters backwards:".$STR 4.";$STR 5=substr($str, -8,-2);Echo"From the last 8th character to the bottom of the 2nd character:".$STR 5.";
2,mb_substr
Mb_substr ($str, $start, $length, $encoding)
$str, the string that needs to be truncated
$start, starting at 0 at the beginning of the truncation
$length, the number of words to intercept
$encoding, page encoding, such as UTF-8,GB2312,GBK
Instance
<? $str= ' Scripting House: Http://www.jb51.net 'echo mb_substr ($str, 0,4, ' utf-8 '); // ?>
3,mb_strlen ()
Get Chinese Length: Mb_strlen ()
Mb_strlen ($str, $encoding)
$str, the string to calculate the length of
$encoding, page encoding, such as UTF-8,GB2312,GBK
<? $str= ' Scripting House: Http://www.jb51.net 'echo mb_strlen ($str, ' utf-8 '); // ?> results show:
4,strrpos ()
Definition and usage
The Strrpos () function finds the position of the last occurrence of a string in another string.
If successful, returns the position, otherwise false.
Grammar
Strrpos (String,find,start)
Parameter description
string is required. Specifies the string to be searched.
Find required. Specifies the character to find.
Start is optional. Specify where to start the search.
Hints and Notes
Note: The function is case-sensitive. For case-insensitive lookups, use Strripos ().
<? PHP Echo Strrpos ("Hello world!", "Wo"); > Output:6
4,strripos ()
Definition and usage
The Strripos () function finds the position of the last occurrence of a string in another string.
If successful, returns the position, otherwise false.
Grammar
Strrpos (String,find,start)
Parameter description
string is required. Specifies the string to be searched.
Find required. Specifies the character to find.
Start is optional. Specify where to start the search.
Hints and Notes
Note: The function is not case sensitive.
<? PHP Echo Strripos ("Hello world!", "WO"); >
PHP Split string