请高手看看,windons下php的中文的问题

zhanglixin 2007-03-30 09:58:41
我主要想生成一个对应的表,但是执行过程中,如果有中文的就会执行两边:最后写到文件中的数据为:
我的这个目录下的文件为:
1000.jpg
站 (文件夹)
我.txt
想生成的目标list为:
1 1000
2 站
3 我
但是结果确实:
1 1
2 站
3 我
4 2
5 3
请高手指点。

下面是代码:

<?php
/**
* 此程序,主要是更改文件目录、文件名称,生成一个对应关系列表
* 目的是去除中文的。
*/
$dirS = "C:/Program Files/Apache Group/Apache2/htdocs/FileSys/";
$dirF = "C:/Program Files/Apache Group/Apache2/htdocs/信息";
//$suffix = "mp3";

//$dirF = "D:/temp/音乐";
$arrFile = explode("/",$dirF);
$stfile = $arrFile[sizeof($arrFile)-1];
if ($handle = opendir($dirF)) {
echo "start------------------------<br>";
/* 这是正确地遍历目录方法 */
$fd = fopen($dirS.$stfile.".txt",'w');
if (!$fd) {
echo "can not open file.";
}
$sourceI = 1;

while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$arrName = array();
$arrName = explode(".",$file);
$num = sizeof($arrName);
if (!$suffix) {
if ($num<2) {
$targetFile = $sourceI;
} else {
$targetFile = $sourceI.".".$arrName[$num-1];
}
} else {
$targetFile = $sourceI.".".$suffix;
}

rename($dirF."/".$file,$dirF."/".$targetFile);
if (!$suffix) {
if ($num>=2) {
$file = str_replace(".".$arrName[$num-1],"",$file);
}
} else {
$file = str_replace(".".$suffix,"",$file);
}

echo "$sourceI $file<br>";
fwrite($fd,$sourceI."\t".$file."\n");
$sourceI ++;

}
}
closedir($handle);
fclose($fd);
}
echo "$dirF";
?>
...全文
214 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanglixin 2007-03-30
  • 打赏
  • 举报
回复
对了,这个程序的目的就是对给定一个目录,修改目录文件名的。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧