Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP自动转换特殊字符?_Php_File Rename - Fatal编程技术网

PHP自动转换特殊字符?

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

我有一个目录列表代码,其中列出了特定目录中的所有文件。文件名有一个包含a-z和0-9以外的特定字符。它就像一个小“i”,上面没有点。文件名为:“ClrmamePro KullanımıEnglish.mp4”。看看“Kullanımı”和“English”。你可以看到“我”和“ı”之间的区别

现在的问题是,当我列出目录时,php会自动将字母“ı”转换为“I”,因此在执行重命名时,会出现错误

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>
"&#68;&#111;&#119;&#110;&#108;&#111;&#97;&#100;&#32;&#71;&#101;&#97;&#114;&#115;&#32;&#111;&#102;&#32;&#87;&#97;&#114;&#32;&#51;&#32;&#45;&#32;&#101;&#83;&#111;&#102;&#116;&#90;&#111;&#110;&#101;&#46;&#119;&#101;&#98;&#109;" exists.
"&#67;&#108;&#114;&#109;&#97;&#109;&#101;&#80;&#114;&#111;&#32;&#75;&#117;&#108;&#108;&#97;&#110;&#305;&#109;&#305;&#32;&#69;&#110;&#103;&#108;&#105;&#115;&#104;&#46;&#109;&#112;&#52;" exists.
"&#70;&#97;&#99;&#101;&#98;&#111;&#111;&#107;&#95;&#32;&#83;&#99;&#105;&#101;&#110;&#99;&#101;&#32;&#97;&#110;&#100;&#32;&#116;&#104;&#101;&#32;&#83;&#111;&#99;&#105;&#97;&#108;&#32;&#71;&#114;&#97;&#112;&#104;&#46;&#77;&#80;&#52;" 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>
"&#68;&#111;&#119;&#110;&#108;&#111;&#97;&#100;&#32;&#71;&#101;&#97;&#114;&#115;&#32;&#111;&#102;&#32;&#87;&#97;&#114;&#32;&#51;&#32;&#45;&#32;&#101;&#83;&#111;&#102;&#116;&#90;&#111;&#110;&#101;&#46;&#119;&#101;&#98;&#109;" exists.
"&#67;&#108;&#114;&#109;&#97;&#109;&#101;&#80;&#114;&#111;&#32;&#75;&#117;&#108;&#108;&#97;&#110;&#305;&#109;&#305;&#32;&#69;&#110;&#103;&#108;&#105;&#115;&#104;&#46;&#109;&#112;&#52;" exists.
"&#70;&#97;&#99;&#101;&#98;&#111;&#111;&#107;&#95;&#32;&#83;&#99;&#105;&#101;&#110;&#99;&#101;&#32;&#97;&#110;&#100;&#32;&#116;&#104;&#101;&#32;&#83;&#111;&#99;&#105;&#97;&#108;&#32;&#71;&#114;&#97;&#112;&#104;&#46;&#77;&#80;&#52;" exists.
</pre>
"Download Gears of War 3 - eSoftZone.webm" exists.
"ClrmamePro Kullanımı English.mp4" exists.
"Facebook_ Science and the Social Graph.MP4" exists.