in PHP mb_substr () function is used to intercept the Chinese and English functions, you can quickly solve the problem of intercepting the length of the specified characters, let me introduce to you.
Hint: MB_SUBSTR is in PHP is not supported by default we need to find php.ini in Windows directory Open edit, search Mbstring.dll, find; Extension=php_mbstring.dll put the front; You can use the MB_SUBSTR function if the number is removed.
Function:mb_substr ($str, $start, $length, $encoding)
$str, the string that needs to be truncated
$start, where the truncation begins
$length, Length (note that this is different from Mb_strimwidth, 1 represents a Chinese character)
$encoding, code, I set it to Utf-8.
Example: Truncate article title, control in 15 words
The code is as follows |
Copy Code |
$str = ' so that my string will not have garbled ^_^ ';
echo "MB_SUBSTR:". Mb_substr ($str, 0, 7, ' utf-8 '); Result: so that my word echo " "; echo "Mb_strcut:". Mb_strcut ($str, 0, 6, ' utf-8 '); Result: this ?> |
The summary appeared he was able to solve the interception of Chinese characters OH
PHP Chinese string intercept