Csnd ice_berg16 (scarecrow for dream searching)
Supports multiple Encoded chinese string truncation functions!
Function csubstr ($ STR, $ start = 0, $ length, $ charset = "UTF-8", $ suffix = true)
{
If (function_exists ("mb_substr "))
Return mb_substr ($ STR, $ start, $ length, $ charset );
$ Re ['utf-8'] = "/[/x01-/x7f] | [/xc2-/xdf] [/X80-/xbf] | [/xe0 -/ xeF] [/X80-/xbf] {2} | [/xf0-/xFF] [/X80-/xbf] {3 }/";
$ Re ['gb2312'] = "/[/x01-/x7f] | [/xb0-/xf7] [/xa0-/xfe]/";
$ Re ['gbk'] = "/[/x01-/x7f] | [/x81-/xfe] [/X40-/xfe]/";
$ Re ['big5'] = "/[/x01-/x7f] | [/x81-/xfe] ([/X40-/x7e] |/xA1-/xfe]) /";
Preg_match_all ($ re [$ charset], $ STR, $ match );
$ Slice = join ("", array_slice ($ match [0], $ start, $ length ));
If ($ suffix) return $ slice ."... ";
Return $ slice;
}
CsndCaaclxf (Some people say my name is very long)
7-bit compression is used for the pure accios before transmission.
This is the function decompression function.
Function decode7bit ($ str7bit)
{
For ($ I = 0; $ I <strlen ($ str7bit); $ I + = 2)
{
$ STR = decbin (hexdec ($ str7bit [$ I]. $ str7bit [$ I + 1]);
$ Arrbin [] = sprintf ("% 08 s", $ Str );
}
// Print_r ($ arrbin );
$ I = 0;
$ Move = 1;
While ($ I <count ($ arrbin )){
If ($ I = 0 ){
$ DST = substr ($ arrbin [$ I], $ move );
} Elseif ($ I % 7 = 0 & $ I! = 0 ){
// Special char
Switch ($ left)
{
Case '20140901 ':
$ Left = '000000 ';
Break;
}
$ Arrbindst [] = $ left;
$ Strdst. = CHR (bindec ($ left ));
$ Move = 1;
$ Left = '';
}
$ DST = substr ($ arrbin [$ I], $ move). $ left;
$ Left = substr ($ arrbin [$ I], 0, $ move );
$ Move ++;
$ I ++;
// Special char
Switch ($ DST)
{
Case '20140901 ':
$ DST = '000000 ';
Break;
}
$ Arrbindst [] = $ DST;
$ Strdst. = CHR (bindec ($ DST ));
}
// Print_r ($ arrbindst );
Return $ strdst;
}