Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: echo'ing UTF-8 characters into Windows command line
    primarykey
    data
    text
    <p>I've ran into a problem, but can't tell whether it is PHP or Windows' command line. When a PHP script tries to echo UTF-8 characters into cmd with UTF-8 codepage loaded, the process stops unexpectedly. Here is a case:</p> <p>test1.php:</p> <pre><code>&lt;?php error_reporting( -1 ); echo 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ', "\n"; echo "OK"; ?&gt; </code></pre> <p>test2.php:</p> <pre><code>&lt;?php error_reporting( -1 ); echo 'ASCII: ABCDEFGHIJKLMNOPQRSTUVWXYZ', "\n"; echo 'UTF-8: АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ', "\n"; echo 'UTF-8: АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ', "\n"; echo "OK"; ?&gt; </code></pre> <p>(Both test1.php and test2.php are saved in UTF-8 without BOM.)</p> <p>The command prompt log:</p> <pre><code>e:\tests&gt;chcp 1252 Active code page: 1252 e:\tests&gt;php -f test1.php АБВГДЕЁЖЗРЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ OK e:\tests&gt;php -f test2.php ASCII: ABCDEFGHIJKLMNOPQRSTUVWXYZ UTF-8: АБВГДЕЁЖЗРЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ UTF-8: АБВГДЕЁЖЗРЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ OK e:\tests&gt;chcp 65001 Active code page: 65001 e:\tests&gt;php -f test1.php e:\tests&gt;php -f test2.php ASCII: ABCDEFGHIJKLMNOPQRSTUVWXYZ UTF-8: АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ e:\tests&gt; </code></pre> <p>While in 1252 mode, all characters get echoed (although not correctly, of course). But in 65001 (UTF-8) mode test1 stalls on the very first character while test2 stalls on the first one of the second UTF-8 row.</p> <p>PHP version is:</p> <pre><code>PHP 5.4.13 (cli) (built: Mar 15 2013 02:07:14) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies </code></pre> <p>Windows is XP SP3.</p> <p>Update:</p> <p>1) If I change <code>echo</code> to:</p> <pre><code>$f = fopen( 'php://stdout', 'w' ); fwrite( $f, ... ); ... close( $f ); </code></pre> <p>it works.</p> <p>2) If I redirect the output:</p> <pre><code>e:\tests&gt;php -f test1.php &gt; out.log </code></pre> <p>it also works (with <code>echo</code>).</p> <p>But what is wrong with the first case?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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