php readdir encoding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
petran76
Forum Newbie
Posts: 2
Joined: Tue Nov 18, 2008 6:07 am

php readdir encoding

Post by petran76 »

Hello.

I am working on my windows pc and trying to read some Greek file names.

while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") {

echo $file; //////// doesn't work

echo utf8_encode($file); /////////// doesn't work

echo mb_check_encoding($file); ///// gives ASCII


}

any idea ?????

thank you.
yoji
Forum Commoner
Posts: 25
Joined: Sun Oct 19, 2008 3:09 am

Re: php readdir encoding

Post by yoji »

try removing the extra = from "!==".. Make it "!="
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: php readdir encoding

Post by VladSun »

yoji wrote:try removing the extra = from "!==".. Make it "!="
8O Why?!?

@petran76
Try to play with iconv()
There are 10 types of people in this world, those who understand binary and those who don't
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: php readdir encoding

Post by Hannes2k »

Hi,
what do you mean with 'doesn't work'? You get no output? A wrong output?

Maybe use 'var_dump($file);' and make sure there is min. one file which fulfills the if statement.
petran76
Forum Newbie
Posts: 2
Joined: Tue Nov 18, 2008 6:07 am

Re: php readdir encoding

Post by petran76 »

Thanks guys a lot for your help I stell haven't founded the solution maybe this will help you.


while (($file = readdir($dh)) !== false) { /// file name = τεστ //test in Greek
if ($file != "." && $file != "..") {

$foo = 'τεστ';
echo $foo; /// prints "τεστ" the charset seems to be ok.

echo $file; // prints "test" i need τεστ

iconv("ASCII","UTF-8",$file); ///// i am not sure if that's wise am sorry

echo $file; // prints "test"

echo utf8_encode($file); // prints "test"

print_r(iconv_get_encoding());
// prints Array ( [input_encoding] => ISO-8859-1 [output_encoding] => ISO-8859-1 [internal_encoding] => ISO-8859-1 )

Thanks again
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: php readdir encoding

Post by VladSun »

petran76 wrote:iconv("ASCII","UTF-8",$file); ///// i am not sure if that's wise am sorry
Instead of ASCII, try other encodings (espec. Greek ones) which are used in your Windows system.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply