Note: Find php.ini in Windows directory Open edit, search Mbstring.dll, find
Extension=php_mbstring.dll the front of the number, so the MB_SUBSTR function can be effective
Example
| The code is as follows |
Copy Code |
|
<?php
$str = ' So my string will not have garbled ^_^ ';
echo "MB_SUBSTR:". Mb_substr ($str, 0, 7, ' utf-8 ');
Result: so that my word
echo "<br>";
echo "Mb_strcut:". Mb_strcut ($str, 0, 6, ' utf-8 ');
Result: this
?> |
As can be seen from the above example, MB_SUBSTR is the word to split the characters, and Mb_strcut is the byte to split the characters, but will not produce half a character phenomenon.
| code is as follows |
copy code |
|
/**
* Implementation text string interception without garbled method
*/
function Getsubstr ($string, $start, $length) {
if (Mb_strlen ($string, ' utf-8 ') > $length) {
$str = Mb_substr ($string, $ Start, $length, ' utf-8 ');
return $str ... ';
}else{
return $string;
}
}
|