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
$str = array_slice($str, 0,4); $str = 'Youer Romantic Sakura Wang Jinsheng ';
?> 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. 🎜 🎜 🎜