-
- $str='Scripting School: http://bbs.it-home.org';
- echo mb_substr($str,0,4,'utf-8');// Intercept the first 5 characters, assuming that the encoding of the php file where this code is located is utf-8
- ?>
-
Copy the code
Output: Programmer's Home
2. Get the Chinese length: mb_strlen()
mb_strlen( $str, $encoding )
$str, the string whose length is to be calculated
$encoding, web page encoding, such as utf-8, GB2312, GBK
Example 2:
-
- $str='Programmer's Home: http://bbs.it-home.org';
- echo mb_strlen($str,'utf-8');//Assumption The encoding of the php file where this code is located is utf-8
- ?>
-
Copy the code
Output: 24
|