Php string truncation function (supports Chinese UTF-8 truncation ). Php Tutorial string truncation function (supports Chinese UTF-8 truncation) the two Chinese character truncation function methods provided in this article are mainly used to solve the problem of utf8 encoding how to correctly intercept Chinese characters. php Tutorial string truncation function (support for Chinese UTF-8 intercept)
The two Chinese character truncation function methods provided in this article are mainly used to solve the problem of how utf8 encoding correctly intercepts Chinese characters,
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
$ Str = "a lap occurs in 12hb kilobytes ";
Echo mb_substr ($ str, 0,5, 'utf-8'); echo'
';
Echo mb_substr ($ str, 5, 3, 'utf-8'); echo'
';
Echo mb_substr ($ str, 8, 4, 'utf-8 ');
?>
Function str_wrap1 ($ str, $ elen = 30)
{
$ Tlen = mb_strlen ($ str, "utf8"); // total number of words
// $ Elen = 8; // each line of string contains 8 characters and 4 Chinese characters
$ Dlen = 0; // Display length of each line
$ Str_wrap = '';
For ($ I = 0; $ I <$ tlen; $ I ++)
{
$ Tmpchar = mb_substr ($ str, $ I, 1, "utf8 ");
If (strlen ($ tmpchar) = 3)
$ Charlen = 2;
Else
$ Charlen = 1;
If ($ dlen <$ elen-1)
{
$ Dlen + = $ charlen;
$ Str_wrap. = $ tmpchar;
}
Else
{
$ Str_wrap. ="
". $ Tmpchar;
$ Dlen = $ charlen;
}
}
Return $ str_wrap;
}
Echo str_wrap1 ($ str, 5 );
?>
Encoding (supporting Chinese UTF-8 truncation) the two Chinese character truncation functions provided in this article mainly aim at how utf8 encoding correctly intercepts Chinese characters...