用了mb_convert_encoding和iconv函数编码转换都不行,php文件编码是UTF-8。
我的dreamweaver环境是utf-8,当我查询中文目录时出现的是打不开路径的情况,这时我就将中文路径进行转码! $path = "F:\\办公";
$path = iconv("utf-8","gbk",$path);
这样就能顺利打开中文路径,当我查出来的文件是中文标题时又出现问题,这是我再将其进行转码 if($dire = scandir($path)){
foreach($dire as $value){
$value = iconv("gbk","utf-8",$value);
echo $value."<br>";
}
} 总的代码是 <?
$path = "F:\\办公";
$path = iconv("utf-8","gbk",$path);
if(is_dir($path)){
if($dire = scandir($path)){
foreach($dire as $value){
$value = iconv("gbk","utf-8",$value);
echo $value."<br>";
}
}else{
echo "没有打开文件夹";
}
}else{
echo "不是路径";
}
?>
------------------------------------------------------------------------------------------
<?php
function refresh($dir){
// $dir=iconv("utf-8","gb2312",$dir);
if ($headle=opendir($dir)){
while (false!==$file=readdir($headle)){
$file=iconv("utf-8","gb2312",$file);
if ($file!='.' && $file!='..'){
echo "文件".$file."在文件夹".$dir."下<br />";
}
}
closedir($headle);
}
}
refresh("D:/AppServ/www/test");
?>
在test文件夹下的文件有中文名字
window是用的GB2312的编码,你的php文件应该用的是UTF-8,所以正如你写的那样,先要转换编码$dir=iconv("utf-8","gb2312",$dir); 但你别忘了,你用的是UTF-8的编码,所以你第六行写错了,把GB2312转换为UTF-8搞倒了吧
<?<a href="https://www.baidu.com/s?wd=php&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPjcYnjI9PWbkuW9hP10v0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHnvP1DsrjckrjDsn1m1Pjf4rf" target="_blank" class="baidu-highlight">php</a>
function refresh($dir){
$dir=iconv("utf-8","gb2312",$dir);
if ($headle=opendir($dir)){
while ($file=readdir($headle)){
$file=iconv("gb2312","utf-8",$file);
if ($file!='.' && $file!='..'){
echo "文件".$file."在文件夹".$dir."下<br />";
}
}
closedir($headle);
}
}
refresh("D:/AppServ/www/test");
?>
遍历windows下的某个目录,将文件目录或文件显示出来。 <?phpini_set('display_errors', 1);$dir_handle=opendir("D:\\UPUPW_AP5.5\\temp\\");//var_dump(mb_detect_order());while(($readdir=readdir($dir_handle))!=false){ $newchar=mb_convert_encoding($readdir,"gb2312","UTF-8"); $char=iconv("UTF-8","gb2312",$readdir); echo $readdir."<br/>";}closedir($dir_handle);?>用了mb_convert_encoding和iconv函数编码转换都不行,php文件编码是UTF-8。
|