PHP scandir filenames with Turkish characters

最后都变了- 提交于 2019-12-11 18:07:51

问题


I am listing documents with PHP scandir. I have problem with some characters like ğ, ı, ş... So this is my code;

$directory = "document";
$scanned_directory = array_diff(scandir($directory, 1), array('..', '.'));
foreach ($scanned_directory as &$value) {
    echo utf8_encode($value);
}

Actually the filename is "şığx.jpg" but the output is "þýðx.jpg". utf8_encode did not solved this. Can you help me? Thank you.


回答1:


utf8_encode will not help you here, as your filesystem is likely in different encoding. Use

echo iconv($in_charset, 'UTF-8', $value);

where $in_charset might be ISO-8859-9, windows-1254, or CP857.

Or if you haven't tried, maybe your filesystem is in utf already ;).



来源:https://stackoverflow.com/questions/26677260/php-scandir-filenames-with-turkish-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!