Skip to content

Instantly share code, notes, and snippets.

@MakStashkevich
Created June 29, 2020 06:35
Show Gist options
  • Save MakStashkevich/eb14e4e80d92eaf0ad0ea8ccc0b2a7fb to your computer and use it in GitHub Desktop.
Save MakStashkevich/eb14e4e80d92eaf0ad0ea8ccc0b2a7fb to your computer and use it in GitHub Desktop.
Roads on PHP to convert unicode to 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('&#x1000;', '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