: This article describes the random Chinese characters intercepted by PHP. For more information about PHP tutorials, see. Today, we will share with you how to use PHP's built-in methods to intercept Chinese characters. Note that the method for intercepting Chinese characters is different from that for intercepting Chinese characters, because a Chinese character may have different numbers of characters due to different encoding, which may be 2 or 3 characters! The following describes the specific methods:
Function getH ($ str ){
// Use the preg_split function to Split Chinese character strings into arrays. The first parameter is regular expression matching. u must be added because it is UTF-8 encoded.
// Substr or mb_substr cannot be used here, because these methods are valid for characters and contain 2 or 3 characters.
$ Str = preg_split ('// U', $ str,-1, PREG_SPLIT_NO_EMPTY );
// Use the shuffle function to disrupt the Chinese character array
// The str_shuffle function cannot be used because the character is broken.
Shuffle ($ str );
// Extract the first four elements from the array and obtain an array of Chinese characters.
$ Str = array_slice ($ str, 0, 4 );
// Implode: concatenates an array into a string.
$ Str = implode ('', $ str );
Return $ str;
}
$ Str = 'romantic cherry blossom Wang Jinsheng ';
GetH ($ str );
?>
Although the tutorial is very simple today, the function is still very practical. if it is useful, I would like to appreciate it!
The above describes the random Chinese characters intercepted by PHP, including some content. I hope my friends who are interested in PHP tutorials can help me.