On Windows, the output of PHP command-line scripts is interpreted according to currently configured code page and console font. Here in Western Europe this often defaults to 850 and bitmap. That means that a script written as UTF-8 (the de-facto standard since PHP/5.4):
<?php
echo 'Café: 1,25 €' . PHP_EOL;
... will typically look this way:
C:\tmp>php test.php
Caf├®: 1,25 Ôé¼
The usual workaround is use a *.bat
wrapper:
@echo off
chcp 65001 > NUL
php test.php
It doesn't fix the font issue but it's normally good enough.
My double question:
Is it possible to set the code page from within PHP so we can omit the wrapper? (Using program execution functions to run
chcp
does not work because it happens in a different process.)Is this a limitation of the console libraries used by PHP? (Node.js scripts always displays correct output from UTF-8 sources no matter the local code page, font aside.)