D
D
Dmaw2020-02-27 13:20:43
PHP
Dmaw, 2020-02-27 13:20:43

Problem with encoding when reading files scandir (mb_convert_encoding, iconv) what's wrong?

Files with Russian names are uploaded to the server in a folder.
I read the folder with files and translate into the desired encoding:

header('Content-Type: text/html; charset= utf-8'); 
setlocale(LC_ALL,'ru_RU.UTF-8');
mb_internal_encoding("UTF-8");

$files = scandir('folder');
foreach($files as $v)
{
    echo mb_convert_encoding($v, "UTF-8", "WINDOWS-1251");
}

And everything was fine until a file with the name "Pyatigorsk" came across, the output on the page turns out to be "Pigorsk", i.e. the mb_convert_encoding function ate two letters. Tried glob to read directory, same thing. I tried to determine the mb_detect_order encoding and substitute different encoding options, nothing helps.

The problem is in the combination of the letters "yat". If we name the file by this name, we get an empty name.
-----------------
It turned out that:
I upload files through Dreamweaver, after that the names of the files in the list on the remote server are displayed in hieroglyphs. It doesn't interfere with the script.
I tried to upload a file named "yat", nothing remained of the name, only a dot and a file extension. This is where I screwed up :)
If anything, this is reg.ru hosting. I went to the admin panel, file manager, uploaded a file from there, the file loaded with Russian letters, the line with mb_convert_encoding was no longer needed in the script.
These are the adventures.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question