Home  >  Article  >  Backend Development  >  PHP randomly intercepts Chinese characters

PHP randomly intercepts Chinese characters

WBOY
WBOYOriginal
2016-07-29 09:08:541724browse

Today I will share with you how to use PHP’s own method to intercept Chinese characters. Please note that the methods of intercepting Chinese characters and intercepting characters are different, because a Chinese character will occupy a different number of characters due to different encodings, and it will be 2 or 3 characters! Let me talk about the specific method:                                                                   Array, first parameter It is a regular match, and u must be added, because it is UTF8 encoding

// You cannot use substr or MB_SUBSTR here, because these methods are effective for characters, Chinese characters account for 2 or 3 characters








$str = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY); // The str_shuffle function cannot be used because that It’s about shuffling the characters

                                                            ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ to

PHP randomly intercepts Chinese characters
                    $str = array_slice($str, 0,4);
$str = 'Youer Romantic Sakura Wang Jinsheng ';

getH($str);

?>

Although today's tutorial is very simple, the functions are still very practical. If you find it useful, please give me a tip🎜! 🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜 🎜🎜 🎜 The above introduces the random interception of Chinese characters in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials. 🎜 🎜 🎜
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn