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:
<?php $str='快乐老家:https://www.xx.net'; echo mb_substr($str,0,4,'utf-8');//截取头5个字,假定此代码所在php文件的编码为utf-8 ?>
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!