Skip to content

Instantly share code, notes, and snippets.

@lovelock
Last active October 9, 2018 03:12
Show Gist options
  • Save lovelock/9056d4cbd60a3791caf8c58b7260bc28 to your computer and use it in GitHub Desktop.
Save lovelock/9056d4cbd60a3791caf8c58b7260bc28 to your computer and use it in GitHub Desktop.
convert unicode characters to utf8
<?php
$str = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) {
if ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UTF-16BE');
}
}, $str);
<?php
$str = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) {
if ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
}, $str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment