Page 1 of 1
php readdir encoding
Posted: Tue Nov 18, 2008 6:13 am
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.
Re: php readdir encoding
Posted: Tue Nov 18, 2008 6:27 am
by yoji
try removing the extra = from "!==".. Make it "!="
Re: php readdir encoding
Posted: Tue Nov 18, 2008 6:51 am
by VladSun
yoji wrote:try removing the extra = from "!==".. Make it "!="

Why?!?
@petran76
Try to play with iconv()
Re: php readdir encoding
Posted: Tue Nov 18, 2008 10:42 am
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.
Re: php readdir encoding
Posted: Wed Nov 19, 2008 6:20 am
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
Re: php readdir encoding
Posted: Wed Nov 19, 2008 7:24 am
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.