Created
June 29, 2020 06:35
-
-
Save MakStashkevich/eb14e4e80d92eaf0ad0ea8ccc0b2a7fb to your computer and use it in GitHub Desktop.
Roads on PHP to convert unicode to characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Because JSON directly supports the \uxxxx syntax the first thing that comes into my mind is: | |
$unicodeChar = '\u1000'; | |
echo json_decode('"'.$unicodeChar.'"'); | |
// Another option would be to use mb_convert_encoding() | |
echo mb_convert_encoding('က', 'UTF-8', 'HTML-ENTITIES'); | |
// or make use of the direct mapping between UTF-16BE (big endian) and the Unicode codepoint: | |
echo mb_convert_encoding("\x10\x00", 'UTF-8', 'UTF-16BE'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment