Skip to content

Instantly share code, notes, and snippets.

@kevinlebrun
Created December 11, 2012 09:32
Show Gist options
  • Save kevinlebrun/4257316 to your computer and use it in GitHub Desktop.
Save kevinlebrun/4257316 to your computer and use it in GitHub Desktop.
Some ways to transform unicode to char in PHP
<?php
function uchrA($str) {
return html_entity_decode(preg_replace('/\\\u([\da-fA-F]{4})/', '&#x\1;', $str));
}
function uchrB($str) {
return utf8_decode(json_decode(sprintf('"%s"', $str)));
}
$str = '\\u00C2';
var_dump(uchrA($str) === uchrB($str));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment