PHP自动转换特殊字符?
我有一个目录列表代码,其中列出了特定目录中的所有文件。文件名有一个包含a-z和0-9以外的特定字符。它就像一个小“i”,上面没有点。文件名为:“ClrmamePro KullanımıEnglish.mp4”。看看“Kullanımı”和“English”。你可以看到“我”和“ı”之间的区别 现在的问题是,当我列出目录时,php会自动将字母“ı”转换为“I”,因此在执行重命名时,会出现错误PHP自动转换特殊字符?,php,file-rename,Php,File Rename,我有一个目录列表代码,其中列出了特定目录中的所有文件。文件名有一个包含a-z和0-9以外的特定字符。它就像一个小“i”,上面没有点。文件名为:“ClrmamePro KullanımıEnglish.mp4”。看看“Kullanımı”和“English”。你可以看到“我”和“ı”之间的区别 现在的问题是,当我列出目录时,php会自动将字母“ı”转换为“I”,因此在执行重命名时,会出现错误 rename(E:/workspace/project/ClrmamePro Kullanimi Engl
rename(E:/workspace/project/ClrmamePro Kullanimi English.mp4,
E:/workspace/project/movie_11.mp4) [<a href='function.rename'>function.rename</a>]: The system cannot find the file specified.
请参阅索引0处的第一个文件。我的目录中的实际文件名是
// https://stackoverflow.com/a/3005240/788324
function prependAmpersandAndPound($n) {
return "&#$n;";
}
function encode($str) {
$str = mb_convert_encoding($str , 'UTF-32', 'UTF-8');
$t = unpack("N*", $str);
$t = array_map(prependAmpersandAndPound, $t);
return implode("", $t);
}
echo "<pre>\n";
$listing = getDirectoryListing('movies');
foreach ($listing as $file) {
echo "\"" . encode($file) . "\" ";
if (file_exists('movies/' . $file)) {
echo "exists.\n";
} else {
echo "does not exist.\n";
}
}
echo '</pre>';
对于
movies
目录中的每个文件,以下代码段将输出文件名以及该文件是否存在。显示的文件名经过编码以正确显示特殊字符
encode
方法将字符串“$file”中的所有字符转换为HTML实体。该方法是对Stack Overflow文章中的解决方案稍加修改的版本。文章中找到的解决方案在我的PHP服务器上不起作用,因此我将prependampersandPound
移到函数外部
<pre>
"Download Gears of War 3 - eSoftZone.webm" exists.
"ClrmamePro Kullanımı English.mp4" exists.
"Facebook_ Science and the Social Graph.MP4" exists.
</pre>
您需要显示您使用的代码。只有目录列表代码。如果你真的需要帮助,那么你必须展示一些代码,否则你希望我们如何帮助你?嘿,伙计们。现在我已经向你提供了我问题的所有细节。比你强。请帮助…您是否尝试过在数组中的每个文件上使用
file\u exists
检查是否存在?PHP是否报告每个文件都存在<代码>回显“”$listing=getDirectoryListing('movies');foreach($file){echo“$file”;如果(file_存在('movies/'.$file)){echo”存在。\n;}否则{echo”不存在。\n;}}echo'代码>
ClrmamePro Kullanımı English.mp4
// https://stackoverflow.com/a/3005240/788324
function prependAmpersandAndPound($n) {
return "&#$n;";
}
function encode($str) {
$str = mb_convert_encoding($str , 'UTF-32', 'UTF-8');
$t = unpack("N*", $str);
$t = array_map(prependAmpersandAndPound, $t);
return implode("", $t);
}
echo "<pre>\n";
$listing = getDirectoryListing('movies');
foreach ($listing as $file) {
echo "\"" . encode($file) . "\" ";
if (file_exists('movies/' . $file)) {
echo "exists.\n";
} else {
echo "does not exist.\n";
}
}
echo '</pre>';
<pre>
"Download Gears of War 3 - eSoftZone.webm" exists.
"ClrmamePro Kullanımı English.mp4" exists.
"Facebook_ Science and the Social Graph.MP4" exists.
</pre>
"Download Gears of War 3 - eSoftZone.webm" exists.
"ClrmamePro Kullanımı English.mp4" exists.
"Facebook_ Science and the Social Graph.MP4" exists.