1

I have either a folder by the name of "同" (doesn't matter which character I use or how many) after pulling it up with php shows the incorrect character or garbled text.

<?php
mb_internal_encoding('utf-8');
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
        echo $file;
    }
}
closedir($handle);
}
echo "同";
?>

Returns:

Folder1index.php��同

It displays 2 'characters' as if it isn't encoded to UTF-8 properly. The browser is processing the page fine as UTF-8 due to the echo of the character in question.

Is this a php/code issue or is something else preventing it displaying properly?(IIS etc.)

1
  • Which encoding is your file-system using for file and directory names? Commented Aug 15, 2011 at 22:08

2 Answers 2

2

The problem is not the UTF-8 encoding of your scripts or the website, the problem most certainly is the encoding of the filenames in your file-system.

You first need to learn which encoding is used on the file-system level. If you get in the know you can re-encode the encoded file-names into UTF-8 (e.g. iconv; mb_convert_encoding). They will display fine then on your website.

You write you're using IIS, so I assume you're running on windows. Please see this related answer and/or the related question What encoding are filenames in NTFS stored as? for more information.

Sign up to request clarification or add additional context in comments.

1 Comment

Looked into the above iconv and mb_convert_encoding which was able to solve my issues. Thank you.
1

Here is an excellent thread on handling utf-8 file names in php - How do I use filesystem functions in PHP, using UTF-8 strings?

In sort, you need to call urlencode/urldecode on file names. However its recommended that you use drupal's transliterate module - Different charset on different server?

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.