Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read non-ASCII characters from CLI standard input
    primarykey
    data
    text
    <p>If I type <code>å</code> in CMD, fgets stop waiting for more input and the loop runs until I press <code>ctrl-c</code>. If I type a "normal" characters like a-z0-9!?() it works as expected.</p> <p>I run the code in CMD under Windows 7 with UTF-8 as charset (<code>chcp 65001</code>), the file is saved as UTF-8 without bom. I use PHP 5.3.5 (cli).</p> <pre><code>&lt;?php echo "ÅÄÖåäö work here.\n"; while(1) { echo '&gt; '. fgets(STDIN); } ?&gt; </code></pre> <p>If I change charset to <code>chcp 1252</code> the loop doesn't break when I type <code>å</code> 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 ╠╦╗.</p> <p><strong>So why does fgets stop waiting for userinput after I have typed åäö?</strong></p> <p><strong>And how can I fix this?</strong></p> <p>EDIT:</p> <p>Also found a strange bug. <code>echo "öäåÅÄÖåäö work here! Or?".chr(10);</code> -> <code>��äåÅÄÖåäö work here! Or? re! Or?</code>. If the first char in echo is <code>å/ä/ö</code> it print strange chars AND the end output duplicate's with <code>n - 1</code> char.. (n = number of åäö in the begining of the string).</p> <p>Eg: <code>echo "åäö 1234" -&gt; ??äö 123434</code> and <code>echo åäöåäö 1234</code> -> <code>??äöåäö 1234 1234</code>. </p> <p><strong>EDIT2 (solved):</strong></p> <p>The problem was <code>chcp 65001</code>, now I use <code>chcp 437</code> (<a href="http://msdn.microsoft.com/en-us/goglobal/cc305156" rel="nofollow">chcp 437</a>). Big thanks to Timothy Martens!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload