小弟的php文件编码原来是GB2312格式的,现在要改成UTF-8编码,直接在php上面打印中文字符是可以打印出来的。
可是当我遍历目录里面的文件的时候却显示为乱码,代码如下:$directory = "/test";
$handle=opendir("$directory");
while (1)
{
$ufile = readdir($handle);
if ($ufile == "") break;
if (($ufile != ".") && ($ufile != "..")
{
echo $ufile."<br>";
}
}当$ufile为中文的时候就会显示为乱码这个是什么原因啊?
比如
$test = "测试";
echo $test;就显示正常。请高手帮忙看下 很急 在线等
可是当我遍历目录里面的文件的时候却显示为乱码,代码如下:$directory = "/test";
$handle=opendir("$directory");
while (1)
{
$ufile = readdir($handle);
if ($ufile == "") break;
if (($ufile != ".") && ($ufile != "..")
{
echo $ufile."<br>";
}
}当$ufile为中文的时候就会显示为乱码这个是什么原因啊?
比如
$test = "测试";
echo $test;就显示正常。请高手帮忙看下 很急 在线等
2 . 设置html的head头utf-8
3 . echo iconv('GB2312', 'UTF-8', $ufile);
$directory = "test";
$handle=opendir("$directory");
while (1)
{
$ufile = readdir($handle);
if ($ufile == "") break;
if (($ufile != ".") && ($ufile != ".."))
{
echo iconv('GB2312', 'UTF-8', $ufile);
}
}
?>