简体   繁体   中英

PHP scandir filenames with Turkish characters

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.

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 ;).

I have the same problem, my system uses CP857. How to convert from CP857 to UTF-8?

This web site https://doc.bccnsoft.com/docs/php-docs-7-en/mbstring.supported-encodings.html claims that PHP 7 does not support CP857. But I do not want to believe this.

I found some other site I will check it: https://www.phpclasses.org/package/1360-PHP-Conversion-between-many-character-set-encodings.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM