管理员
|
PHP GBK UTF8互转
@tea function gbk_to_utf8($str){ return mb_convert_encoding($str, 'utf-8', 'gbk'); } function utf8_to_gbk($str){ return mb_convert_encoding($str, 'gbk', 'utf-8'); } php识别中文编码并自动转换为UTF-8 php自动识别编码,若里面有中文的话,将其转换为UTF-8就最好了,因为中文在Gbk编辑情况情况下,有可能会乱码,这个和客户端和服务端编码都有关系,为了避免乱码,我们可以使用下面的函数将其自动转换为UTF8国际标准编码: <?php function characet($data){ if( !empty($data) ){ $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ; if( $fileType != 'UTF-8'){ $data = mb_convert_encoding($data ,'utf-8' , $fileType); } } return $data; } ?> PHP——字符串统一转码为GBK,自动判断是否UTF8并转码 public static function strToGBK($strText) { $encode = mb_detect_encoding($strText, array('UTF-8','GB2312','GBK')); if($encode == "UTF-8") { return @iconv('UTF-8','GB18030',$strText); } else { return $strText; } } mb_detect_encoding:检测字符的编码 PHP GBK UTF8互转 http://www.oschina.net/code/snippet_1443477_48480 标签:GBK UTF8 编码转换 php识别中文编码并自动转换为UTF-8 http://www.codefans.net/articles/1272.shtml PHP通过iconv将字符串从GBK转换为UTF8字符集 http://www.jb51.net/article/27743.htm 各种编码UNICODE、UTF-8、ANSI、ASCII、GB2312、GBK详解 http://blog.csdn.net/lvxiangan/article/details/8151670 站长工具 > 日常实用工具 |
管理员
|
地板#
发布于:2017-03-10 02:54
9.0.0 Chapters
http://www.unicode.org/versions/Unicode9.0.0/ 1 Introduction 2 General Structure 3 Conformance 4 Character Properties 5 Implementation Guidelines 6 Writing Systems and Punctuation 7 Europe-I 8 Europe-II 9 Middle East-I 10 Middle East-II 11 Cuneiform and Hieroglyphs 12 South and Central Asia-I 13 South and Central Asia-II 14 South and Central Asia-III 15 South and Central Asia-IV 16 Southeast Asia 17 Indonesia and Oceania 18 East Asia 19 Africa 20 Americas 21 Notational Systems 22 Symbols 23 Special Areas and Format Characters 24 About the Code Charts |
管理员
|
4楼#
发布于:2017-03-10 03:11
Table E-1. G Source Documentation
Name Description of Source G0 GB 2312-80 G1 GB/T 12345-90 G3 GB 7589-87 unsimplified forms G5 GB 7590-87 unsimplified forms G7 General Purpose Hanzi List for Modern Chinese Language, and General List of Simplified Hanzi GS Singapore Characters G8 GB 8565.2-88 G9 GB 18030-2005 GE GB/T 16500-1998 GH GB/T 15564-1995 Code of Chinese Ideogram set for teletext broadcasting Hong Kong subset GK GB 12052-89 Korean Character Coded Character Set for Information Interchange G4K Siku Quanshu GBK Chinese Encyclopedia GCH Ci Hai GCY Ci Yuan GCYY Chinese Academy of Surveying and Mapping Ideographs GDZ Geographic Publishing House Ideographs GFC Modern Chinese Standard Dictionary GFZ Founder Press System GGFZ Tongyong Guifan Hanzi Zidian GGH Gudai Hanyu Cidian GHC Hanyu Dacidian GHZ Hanyu Dazidian ideographs GIDC ID system of the Ministry of Public Security of China, 2009 GJZ Commercial Press Ideographs GKX Kangxi Dictionary ideographs 9th edition (1958) including the addendum GRM People’s Daily Ideographs GXC Xiandai Hanyu Cidian GXH Xinhua Zidian GWZ Hanyu Dacidian Publishing House Ideographs GZFY Hanyu Fangyan Dacidian GZH Zhonghua Zihai GZJW Yinzhou Jinwen Jicheng Yinde Han Unification History http://www.unicode.org/versions/Unicode9.0.0/appE.pdf |
管理员
|
5楼#
发布于:2017-03-31 22:32
Unicode
<?php date_default_timezone_set('PRC'); sleep(5);//php 睡5秒 echo date('Y-m-d H:i:s',time());//获取当前系统时间的时间戳 echo '<hr />'; echo date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']);//得到请求此php脚本时的时间戳 ?> http://www.jb51.net/article/57562.htm http://tool.chinaz.com/tools/unixtime.aspx http://tool.chinaz.com/tools/unicode.aspx |
管理员
|
6楼#
发布于:2017-04-29 14:36
用PHP将Unicode 转化为UTF-8
function unescape($str) { $str = rawurldecode($str); preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U",$str,$r); $ar = $r[0]; //print_r($ar); foreach($ar as $k=>$v) { if(substr($v,0,2) == "%u"){ $ar[$k] = iconv("UCS-2BE","UTF-8",pack("H4",substr($v,-4))); } elseif(substr($v,0,3) == "&#x"){ $ar[$k] = iconv("UCS-2BE","UTF-8",pack("H4",substr($v,3,-1))); } elseif(substr($v,0,2) == "&#") { $ar[$k] = iconv("UCS-2BE","UTF-8",pack("n",substr($v,2,-1))); } } return join("",$ar); } echo unescape("紫星蓝"); 今天有用户反馈,表单系统用户提交的数据中文会乱码。测试发现问题出在 iconv 转换上。 iconv('UCS-2', 'GBK', '中文') Google 搜索发现,原因是 Linux 服务器上 UCS-2 编码方式与 Winodws 不一致。 于是,我改成 iconv('UCS-2BE', 'GBK', '中文') 试试,中文正常了 以下是有关两个平台 UCS-2 编码的潜规则: 1, UCS-2 不等于 UTF-16。 UTF-16 每个字节使用 ASCII 字符范围编码,而 UCS-2 对每个字节的编码可以超出 ASCII 字符范围。UCS-2 和 UTF-16 对每个字符至多占两个字节,但是他们的编码是不一样的。 2, 对于 UCS-2, windows 下默认是 UCS-2LE。用 MultibyteToWidechar(或者A2W)生成的是 UCS-2LE 的 unicode。windows记事本可以将文本保存为 UCS-2BE,相当于多了层转换。 3, 对于 UCS-2, linux 下默认是 UCS-2BE。用iconv(指定UCS-2)来转换生成的是 UCS-2BE 的 unicode。如果转换windows平台过来的 UCS-2, 需要指定 UCS-2LE。 4, 鉴于windows和linux等多个平台对 UCS-2 的理解不同(UCS-2LE,UCS-2BE)。MS 主张 unicode 有个引导标志(UCS-2LE FFFE, UCS-2BE FEFF),以表明下面的字符是 unicode 并且判别 big-endian 或 little-endian。 所以从 windows 平台过来的数据发现有这个前缀,不用慌张。 5, linux 的编码输出,比如从文件输出,从 printf 输出,需要控制台做适当的编码匹配(如果编码不匹配,一般和该程序编译时的编码有若干关系),而控制台的转换输入需要查看当前的系统编码。比如控制台当前的编码是 UTF-8, 那么 UTF-8 编码的东西能正确显示,GBK 就不能;同样,当前编码是 GBK, 就能显示 GBK 编码,后来的系统应该更智能的处理好更多的转换了。不过通过 putty 等终端还是需要设置好终端的编码转换以解除乱码的烦恼。 PHP中对汉字进行UNICODE编码和解码的实现 //将内容进行UNICODE编码 function unicode_encode($name) { $name = iconv('UTF-8', 'UCS-2', $name); $len = strlen($name); $str = ''; for ($i = 0; $i < $len - 1; $i = $i + 2) { $c = $name[$i]; $c2 = $name[$i + 1]; if (ord($c) > 0) { // 两个字节的文字 $str .= '\u'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16); } else { $str .= $c2; } } return $str; } $name = 'MY,你大爷的'; $unicode_name=unicode_encode($name); echo '<h3>'.$unicode_name.'</h3>'; // 将UNICODE编码后的内容进行解码 function unicode_decode($name) { // 转换编码,将Unicode编码转换成可以浏览的utf-8编码 $pattern = '/([\w]+)|(\\\u([\w]{4}))/i'; preg_match_all($pattern, $name, $matches); if (!empty($matches)) { $name = ''; for ($j = 0; $j < count($matches[0]); $j++) { $str = $matches[0][$j]; if (strpos($str, '\\u') === 0) { $code = base_convert(substr($str, 2, 2), 16, 10); $code2 = base_convert(substr($str, 4), 16, 10); $c = chr($code).chr($code2); $c = iconv('UCS-2', 'UTF-8', $c); $name .= $c; } else { $name .= $str; } } } return $name; } echo 'MY,\u4f60\u5927\u7237\u7684 -> '.unicode_decode($unicode_name); http://www.cnblogs.com/xiangxiaodong/archive/2012/10/25/2739307.html http://blog.csdn.net/qdujunjie/article/details/45079329 |