php ascii 字符转换 (汉字及特殊字符) 宽字符 (uft8/unicode)
?
有点像现在流行的输入法中的特殊字符。
?
1. 英文字母或者数字转ascii 效果如上
?
class:
?
?可以通过css控制字符大小。具体见附件。
?
2. 汉字转ascii 效果为 “星期天 ” 就是 “星期天”
?
function encode($c){ $len = strlen($c); $a = 0; while ($a =0 && ord($c{$a})=192 && ord($c{$a})=224 && ord($c{$a})=240 && ord($c{$a})=248 && ord($c{$a})=252 && ord($c{$a})=254 && ord($c{$a})<=255) { //error $ud = false; } $scill .= $ud;; } return $scill;}echo encode('日'); // 日 浏览器默认会解读,所以要看源代码
?
3. utf-8 unicode 互转
?
// utf8 - unicodefunction utf8_unicode($c) { switch(strlen($c)) { case 1: return ord($c); case 2: $n = (ord($c[0]) & 0x3f) << 6; $n += ord($c[1]) & 0x3f; return $n; case 3: $n = (ord($c[0]) & 0x1f) << 12; $n += (ord($c[1]) & 0x3f) << 6; $n += ord($c[2]) & 0x3f; return $n; case 4: $n = (ord($c[0]) & 0x0f) << 18; $n += (ord($c[1]) & 0x3f) << 12; $n += (ord($c[2]) & 0x3f) <
?12); $str.=chr(0x80 | $c>>6 & 0x3f); $str.=chr(0x80 | $c & 0x3f); } else if ($c >18); $str.=chr(0x80 | $c>>12 & 0x3f); $str.=chr(0x80 | $c>>6 & 0x3f); $str.=chr(0x80 | $c & 0x3f); } return $str; }echo u2utf8('20197');?>
??
?
?
?
