后端开发|php教程
php,字符串,中英文
后端开发-php教程
/** * * 中英混合字符串长度判断 * @param unknown_type $str * @param unknown_type $charset */function strLength($str, $charset = utf-8) { if ($charset == utf-8) $str = iconv ( utf-8, gb2312, $str ); $num = strlen ( $str ); $cnNum = 0; for($i = 0; $i 127) {$cnNum ++;$i ++; } } $enNum = $num - ($cnNum * 2); $number = ($enNum / 2) + $cnNum; return ceil ( $number );}
/** * * 中英混合的字符串截取 * @param unknown_type $sourcestr * @param unknown_type $cutlength */function cut_str($sourcestr, $cutlength) { $returnstr = \; $i = 0; $n = 0; $str_length = strlen ( $sourcestr ); //字符串的字节数 while ( ($n < $cutlength) and ($i = 224) //如果ASCII位高与224, {$returnstr = $returnstr . substr ( $sourcestr, $i, 3 ); //根据UTF-8编码规范,将3个连续的字符计为单个字符 $i = $i + 3; //实际Byte计为3$n ++; //字串长度计1 } elseif ($ascnum >= 192) //如果ASCII位高与192, {$returnstr = $returnstr . substr ( $sourcestr, $i, 2 ); //根据UTF-8编码规范,将2个连续的字符计为单个字符 $i = $i + 2; //实际Byte计为2$n ++; //字串长度计1 } elseif ($ascnum >= 65 && $ascnum $cutlength) { $returnstr = $returnstr . "..."; //超过长度时在尾处加上省略号 } return $returnstr;}
68mall 源码,在ubuntu怎么联网,tomcat7配置安装,审查元素 爬虫,php标量数据,SEO深度解析 痞子瑞 电子版lzw