crazywhalecc / static-php-cli

Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included.
https://static-php.dev
MIT License
1.26k stars 217 forks source link

Issues printing Unicode characters. #392

Closed comanche closed 6 months ago

comanche commented 6 months ago

Cannot print Unicode characters properly on the CLI.

Create this test.php file:

echo "\u{1000}";

Download micro.sfx from php-8.3.4-micro-win.zip

Extract the micro.sfx from the php-8.3.4-micro-win.zip to the same directory as test.php.

Create the test.exe.

copy /b micro.sfx + test.php test.exe

Run test.exe.

Expected result:

က

Actual result:

က

Running php test.php produces က as expected.

If both outputs of running the test.php directly with PHP and the test.exe and are redirect to a file (e.g. php test.php > out1.txt and test.exe > out2.txt), BOTH outputs are identical. They both have the following in HEX:

E1 80 80
crazywhalecc commented 6 months ago

On Windows, you can use chcp 65001 to change code page in cmd. Simplist way is changing current code page:

exec('CHCP 65001');
echo "\u{1000}";

And you can also use iconv to convert code.