0

I have a code which read FTP dir with directories with names such as (example):

"John_Trumph_USA_bb44cc"

code:

$dh = opendir("ftp://10.200.1.1/rt");
while($filename = readdir($dh))
{
echo " ".$filename."\n <br>";
?>

But in final result I have only:

"_Trumph_USA_bb44cc"

Where is the first word "John"?

3
  • Once i experienced this problem and It was an encoding one. Try to use setlocale(LC_ALL, 'US');. In second parameter put your files encoding. Commented Dec 5, 2019 at 7:29
  • like that? $dh = opendir("10.200.1.1/rt", setlocale(LC_ALL, 'US')); In listing i have names of dir in russian and english. Commented Dec 5, 2019 at 11:37
  • did setlocale fixed your problem? @Pavel Commented Dec 6, 2019 at 18:53

2 Answers 2

1

Try changing the encoding like this.

setlocale(LC_ALL, 'ru_RU');

$dh = opendir("ftp://10.200.1.1/rt");
while($filename = readdir($dh))
{
echo " ".$filename."\n <br>";
?>
Sign up to request clarification or add additional context in comments.

3 Comments

Check if language is installed on you server via locale -a You can install it via sudo locale-gen --purge en_US.UTF-8 ru_RU
I see russian words and english word in my list. But I didnt see first russian word in it.
Installing the correct UTF-8 locale will fix the issue.
0

Sorry, I can't comment so I've had to leave an answer

Have you tried using the example code from the PHP documentation ? The first example here is trying to do exactly what you are.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.