If I type å
in CMD, fgets stop waiting for more input and the loop runs until I press ctrl-c
. If I type a "normal" characters like a-z0-9!?() it works as expected.
I run the code in CMD under Windows 7 with UTF-8 as charset (chcp 65001
), the file is saved as UTF-8 without bom. I use PHP 5.3.5 (cli).
<?php
echo "ÅÄÖåäö work here.\n";
while(1)
{
echo '> '. fgets(STDIN);
}
?>
If I change charset to chcp 1252
the loop doesn't break when I type å
and it print "> å" but the "ÅÄÖåäö work here" become "ÅÄÖåäö work here!". And I know that I can change the file to ANSI, but then I can't use special characters like ╠╦╗.
So why does fgets stop waiting for userinput after I have typed åäö?
And how can I fix this?
EDIT:
Also found a strange bug.
echo "öäåÅÄÖåäö work here! Or?".chr(10);
-> ��äåÅÄÖåäö work here! Or? re! Or?
.
If the first char in echo is å/ä/ö
it print strange chars AND the end output duplicate's with n - 1
char.. (n = number of åäö in the begining of the string).
Eg: echo "åäö 1234" -> ??äö 123434
and echo åäöåäö 1234
-> ??äöåäö 1234 1234
.
EDIT2 (solved):
The problem was chcp 65001
, now I use chcp 437
(chcp 437).
Big thanks to Timothy Martens!
å
in the CMD outside of the php? 2) It is only logical that an UTF-8Å
is not the same as an windows-1252Å
thus the resultingÃ
. But what happens if you try to convert the PHP file into windows-1252? – Deadwoodchcp 65001
(UTF-8) andchcp 1252
. 2) I use UTF-8 in cmd AND as charset for the PHP file. If I use windows-1252 in the PHP file nothing changes. I think the problem is in windows/PHP. When I usechcp 1252
it work for ÅÄÖ (even if the PHP file is UTF-8), but then I can't use ╠╦╗ etc. – Caucasusvar_dump(fgetc(STDIN))
-> bool(false);var_dump(fgets(STDIN))
-> bool(false); when I typeå
(or äö). Else it work. – Caucasus