Solution to php Chinese interception of garbled characters: First obtain the length of the Chinese string through the mb_strlen function; then use PHP's built-in function mb_substr to intercept the string.
The operating environment of this tutorial: windows10 system, php5.6. This article is applicable to all brands of computers.
Recommendation: "PHP Video Tutorial"
Solution to garbled Chinese character strings when intercepted by PHP
needs to be intercepted For string requirements, the first thing that comes to mind is substr(), but there will be problems with garbled characters. So if you want to intercept a Chinese string, you can use PHP's built-in function Chinese interception: mb_substr(), which is
mb_substr( $str, $start, $length, $encoding )
$str: Chinese string that needs to be intercepted;
$start: interception start parameter, starting from 0;
$length: the number of words to be intercepted;
$ encoding: Web page encoding, such as UTF-8, GB2312, GBK;
In addition, a function to obtain the length of the Chinese string is attached to obtain the Chinese length: mb_strlen()
mb_strlen( $str, $encoding ) $str : 中文字符串 ; $encoding : 网页编码,如UTF-8,GB2312,GBK;
The above is the detailed content of What to do if php Chinese intercepts garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor
