When I run a script in the terminal containing <?php echo "पीएचपी";
, it displays garbage characters instead of the emoji and foreign text.
Specifically, it displays 🚀पीएचपी
.
However, running a Node.js script containing console.log("पीएचपी")
correctly displays the emoji and the foreign text as पीएचपी
.
How can I echo/print emojis and the foreign text properly so they display as intended in the CLI when using PHP?
Any suggestions on how to resolve this and get PHP to display emojis and unicode text correctly in the terminal?
This scenario has been tested using Windows Terminal (Powershell 7), cmd and GitBash(MINGW64) terminal
Running chcp
in my windows terminal returns 65001 (which is utf-8). So the terminal itself is configured UTF-8 properly. Reference for chcp
: https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers?redirectedfrom=MSDN
Minimal Reproducible Example:
- Run
chcp 65001
in Windows Terminal/cmd. - Run
chcp
again to make sure it returnsActive code page: 65001
. - Run the php script below(make sure
extension=mbstring
is enabled in php.ini):
<?php
$utf8_string = "पीएचपी";
$detected_encoding = mb_detect_encoding($utf8_string);
echo "Detected encoding[$utf8_string]: " . $detected_encoding;
- I still got this displayed:
Detected encoding[🚀पीएचपी]: UTF-8
ADDENDUM: I am using PHP7.0 . It works in PHP 8.2 but not PHP 7.0