当前位置:首页 > PHP教程 > PHP高级教程

PHP字符编码问题之GB2312VSUTF-8解决方法

看代码:
复制代码 代码如下:

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title> new document </title>
<meta name="author" content=""/>
<meta name="keywords" content=""/>
<meta name="description" content=""/>
<link rel="stylesheet" type="text/css" href="" />
</head>

<body>
<?php
$string1 = "i am a phper";
$string2 = "这网站是硕编程";
print_r(str_split($string1));
echo "<br />";
print_r(str_split($string2,4));
?>
</body>
</html>

测试结果打出我所料——中文乱码

  why?why?why?why?乱码是什么?什么事乱码?给我解释解释,什么,是%&的乱码!

  因为英文无乱码,只有中文乱码,首先想到了编码的问题,于是突然想起来utf-8的编码是utf-8需要3个字节,死马当活马医吧!

  于是  print_r(str_split($string2,4));这句中的4 ,就被换成了6,于是乎——看结果

  同样,你也可以试试将编码的charset的utf-8改成gb2312,因为unicode的编码是需要2字节的,所以说gb2312的编码比utf-8能够节约1/3的空间,但是如果你要兼容繁体中文、韩文、日文的其他的语言就需要使用utf-8了。



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐