/*
Php uses ISO-8859-1 to process strings, that is, to process strings in a single byte. The Chinese code is a multi-byte character. When substr is used,
Strlen, str_peplace, and other functions are prone to errors. Special Chinese operations must be processed using a set of Chinese processing functions. Below is
The substr and strlen operation functions of GBK. The former does not use a negative number as the start value like the substr of php. lenght.
To constantly improve these functions to achieve efficient and practical use.
*/
// Gbk str handle
Function gbk_substr (& $ str, $ start, $ length =-1)
{
If ($ length = 0) return "";
If ($ start <0) $ start = 0;
For ($ I = 0; $ I <$ start; $ I ++)
{
If (ord (substr ($ str, $ I, 1)> = 0x81)
{
$ Start ++;
$ I ++;
}
}
If ($ start> gbk_strlen ($ str) return "";
$ Ss = "";
If ($ length =-1)
{
$ Ss = substr ($ str, $ start );
}
Else
{
Echo "leghth =". $ length ."";
For ($ I = $ start; $ I <$ start + $ length; $ I ++)
{
If (ord (substr ($ str, $ I, 1)> = 0x81)
{
$ Ss. = substr ($ str, $ I, 2 );
$ Length ++;
$ I ++;
}
Else
{
$ Ss. = substr ($ str, $ I, 1 );
}
}
}
Return $ ss;
}
Function gbk_strlen (& $ str)
{
$ Len = strlen ($ str );
$ L = 0;
For ($ I = 0; $ I <$ len; $ I ++)
{
If (ord (substr ($ str, $ I, 1)> = 0x81) $ I ++;
$ L ++;
}
Return $ l;
}
Function gb2312_strlen (& $ str)
{
$ Len = strlen ($ str );
$ L = 0;
For ($ I = 0; $ I <$ len; $ I ++)
{
If (ord (substr ($ str, $ I, 1)> = 0xa1) $ I ++;
$ L ++;
}
Return $ l;
}
?>