-
-
//--------------------------------- ------------------ - //Function name: csubstr
- //Function: truncate string, one Chinese character counts as two characters, and English character counts as one character
- //For GBK (GB2312) encoded website
- // Parameters: $str ---- original string
- // $start ---- starting length
- // $len ---- intercepted length
- // Return value: intercepted The last string
- //Organized by: itlearner
- //---------------------------------------- ----------------
function csubstr($str, $start, $len)
- {
- if ($len >= strlen( $str)) return $str;
- $tmpstr = "";
- $len= ($len < strlen($str)) ? $len : strlen($str);
- for ($i= $start; $ i < $len; $i ++)
- {
- if (ord(substr($str, $i, 1)) > 0xa0)
- {
- $tmpstr .= substr($str, $i, 2) ;
- $i ++;
- } else
- {
- $tmpstr .= substr($str, $i, 1);
- }
- }
- $tmpstr .= "...";
- return $tmpstr;
- }
- ?>
-
Copy code
|