How to intercept the first digits of Chinese string in php, usage of mb_substr()

1. Chinese interception: mb_substr()

mb_substr( $str, $start, $length, $encoding )

$str, the string that needs to be truncated

$start, the beginning 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:

code show as below:

<?php

$str='你好大哥:https://www.xx.net';

echo mb_substr($str,0,4,'utf-8');//截取头5个字,假定此代码所在php文件的编码为utf-8

?>

结果显示:你好大哥

Guess you like

Origin blog.csdn.net/qq_32450471/article/details/131311889