Home>Article>Backend Development> How to intercept the first digits of Chinese string in php
php method to intercept the first few digits of a Chinese string: first create a PHP sample file; then intercept the first few digits of the Chinese string through the "mb_substr($str,0,4,'utf-8');" method Just a few people.
#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to intercept the first digits of a Chinese string in php?
Chinese interception: mb_substr()
mb_substr( $str, $start, $length, $encoding )
$str, the string that needs to be truncated
$start, the starting point of truncation, the starting point is 0
$length, the number of words to be intercepted
$encoding, web page encoding, such as utf-8, GB2312, GBK
Example:
The code is as follows:
The results show: Happy Hometown
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to intercept the first digits of Chinese string in php. For more information, please follow other related articles on the PHP Chinese website!