在PHP中可以通过mb_substr函数来截取中文并且不会乱码,其使用语法是“mb_substr (string $str , int $start [, int $length = NULL [, string ...)”。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
php 中文截取怎么能不乱码?
在PHP中可以通过mb_substr函数来截取中文并且不会乱码。
mb_substr() 函数返回字符串的一部分,之前我们学过 substr() 函数,它只针对英文字符,如果要分割的中文文字则需要使用 mb_substr()。
注释:如果 start 参数是负数且 length 小于或等于 start,则 length 为 0。
语法
mb_substr ( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] ) : string

推荐学习:《PHP视频教程》
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!
Comment ouvrir le fichier php
Comment supprimer les premiers éléments d'un tableau en php
Que faire si la désérialisation php échoue
Comment connecter PHP à la base de données mssql
Comment connecter PHP à la base de données mssql
Comment télécharger du HTML
Comment résoudre les caractères tronqués en PHP
Comment ouvrir des fichiers php sur un téléphone mobile