This article summarizes the PHP Chinese string interception method, very practical skills. The specific methods are analyzed as follows:
1, the use of mbstring Extension Library MB_SUBSTR interception will not appear garbled.
2, write the interception function, but the efficiency is not as high as the Mbstring expansion library.
3, if only for the output interception of the string, can be implemented as follows: substr ($STR, 0,). chr (0).
SUBSTR () function can split the text, but the text to be divided if the inclusion of Chinese characters tend to encounter problems, you can use MB_SUBSTR ()/mb_strcut This function, Mb_substr ()/mb_strcut usage and substr () similar, Just in Mb_substr ()/mb_strcut to add more than one parameter to set the string encoding, but the general server did not open Php_mbstring.dll, need to php.ini in the Php_mbstring.dll to open.
Give 2 examples:
(1) Mb_substr example
(2) Mb_strcut example
The above example shows that mb_substr splits characters by word, while mb_strcut splits characters by bytes, but does not produce a half-character phenomenon.
PHP implementation of the text string interception without garbled method:
I hope this article is helpful to everyone's PHP programming. For more information on programming language Tutorials , please visit e-mentor Web.
A summary of examples of Chinese string interception methods in PHP