ChinaUnix.net
相关文章推荐:

php utf8 截取字符串 数字字母

看到网上很多人提到,截取中英混排字符串时候宽度不一致使页面难看的问题。我在一位仁兄写的截取utf8字符串函数基础上,稍微微更改了一下实现了按实际长度来截取中英混排字符串。大致按一个汉语字符的宽度相当于两个英文字符来计算。 具体实现如下: function subutf8($string, $length = 80, $etc = '...') { $strcut = ''; $strLength = 0; $width = 0; if(strlen($string) > $length) { //将$length换算成实际UT...

by hdyzyb04 - php文档中心 - 2007-10-02 03:13:31 阅读(1768) 回复(0)

相关讨论

给一个字符串,怎么判断它是什么编码呢?php有一个函数:mb_detect_encoding。不过这个东西需要有mb_string库,不是到处都能用的。 - 自己写的函数: - function is_utf8($string) { return preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x8...

by fan12 - PHP - 2008-09-15 07:58:17 阅读(1378) 回复(0)

$str = iconv("utf-8","GBK",$str); 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8780/showart_316115.html

by linxh - php文档中心 - 2007-06-06 18:06:50 阅读(797) 回复(0)

文件: utf8字符串截取.rar 大小: 0KB 下载: 下载 /** * utf8字符串截取 * @author kokko * @version 1.0 2007-10-26 * @param string $string * @param int $length * @param string $etc * @param bool $count_words * @return string */ function func_subString( $string,$length = 80,$etc='...',$count_words = true ) { mb_internal_encoding("utf-8"); $wordscut=""; if ($length == 0) return ''; if ( str...

by ClearWind - php文档中心 - 2007-12-07 15:06:34 阅读(1134) 回复(0)

ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); class String { function subString_utf8($str, $start, $lenth) { $len = strlen($str); $r = array(); $n = 0; $m = 0; for($i = 0; $i = $lenth){ break; } } } return $r; } // End subString_utf8 }// End String echo ''; echo...

by nothing9 - php文档中心 - 2006-09-06 19:31:43 阅读(641) 回复(0)

[来源] http://wleige.cublog.cn /** * Filename : String.php * Author : Dummy | Zandy * Email : [email=lianxiwoo@gmail.com]lianxiwoo@gmail.com[/email] | hotmail.com * Create : 200512 * LastMod : 2005 * Usage : */ ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); class String { function subString_utf8($str, $start, $lenth) { $len = strlen($str); ...

by cnscn2008 - php文档中心 - 2006-01-24 13:32:29 阅读(666) 回复(0)

php代码:-------------------------------------------------------------------------------- /** * Filename : String.php * Author : Dummy | Zandy * Email : [email=lianxiwoo@gmail.com]lianxiwoo@gmail.com[/email] | hotmail.com * Create : 200512 * LastMod : 2005 * Usage : */ ini_set('display_errors', 1); error_reporting(E_ALL ^ E_NOTICE); class String { function subString_utf8($str, $st...

by wleige - php文档中心 - 2006-01-23 17:35:50 阅读(742) 回复(0)

村里看到的,不错的东东^_^ /** * Filename : String.php * Author : Dummy | Zandy * Email : [email=lianxiwoo@gmail.com]lianxiwoo@gmail.com[/email] | hotmail.com * Create : 200512 * LastMod : 2005 * Usage : */ ini_set(''display_errors'', 1); error_reporting(E_ALL ^ E_NOTICE); class String { function subString_utf8($str, $start, $lenth) { $len = strlen($str); $r = ...

by 放弃思考 - php文档中心 - 2005-12-31 13:43:09 阅读(795) 回复(0)

问题: 保存为utf-8格式的php文件运行时header函数 Cannot modify header information Unicode规范中有一个BOM的概念。BOM——Byte Order Mark,就是字节序标记。在 浅谈Unicode 有关于BOM的说明: 在UCS 编码中有一个叫做"ZERO WIDTH NO-BREAK SPACE"的字符,它的编码是FEFF。而FFFE在UCS中是不存在的字符,所以不应该出现在实际传输中。UCS规范建议我们在传输字节流前,先传输字符"ZERO WIDTH NO-BREAK SPACE"。这样如果接收者收...

by linxh - php文档中心 - 2007-04-27 11:18:47 阅读(603) 回复(0)

php中GBK和utf8编码处理 作者:heiyeluren 来源: [color="#0000ff"]heiyeluren的blog 2008-01-21 最后更新:2008-01-21 15:14:07 收藏到网摘: 一、编码范围 1. GBK (GB2312/GB18030) \x00-\xff GBK双字节编码范围 \x20-\x7f ASCII \xa1-\xff 中文 \x80-\xff 中文 2. utf-8 (Unicode) \u4e00-\u9fa5 (中文) \x3130-\x318F (韩文 \xAC00-\xD7A3 (韩文) \u0800-\u4e00 (日文) ps: 韩文是大于[\u...

by hkebao - php文档中心 - 2009-07-23 11:48:32 阅读(976) 回复(0)

php中GBK和utf8编码处理 一、编码范围 1. GBK (GB2312/GB18030) x00-xff GBK双字节编码范围 x20-x7f ASCII xa1-xff 中文 x80-xff 中文 2. utf-8 (Unicode) u4e00-u9fa5 (中文) x3130-x318F (韩文 xAC00-xD7A3 (韩文) u0800-u4e00 (日文) ps: 韩文是大于[u9fa5]的字符 正则例子: PLAIN TEXT php: preg_replace("/([x80-xff])/","",$str); preg_replace("/([u4e00-u9fa5])/","",$str); 二、代码例子 PLAIN TEXT php: //判断内...

by chencs - php文档中心 - 2008-12-02 15:38:09 阅读(1235) 回复(0)