Skip to content

Instantly share code, notes, and snippets.

@saji89
Created October 15, 2015 06:41
Show Gist options
  • Save saji89/377b1a56f62b8afcc7a1 to your computer and use it in GitHub Desktop.
Save saji89/377b1a56f62b8afcc7a1 to your computer and use it in GitHub Desktop.
Unicode encoded value conversion
<?php
function unescapeUTF8EscapeSeq($str)
{
return preg_replace_callback("/\\\u([0-9a-f]{4})/i",
create_function('$matches',
'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_QUOTES, \'UTF-8\');'
), $str);
}
$unicodeEncodedvalue = '\u041d\u0438\u043a\u043e\u043b\u0430\u0439 \u0420\u0435\u0448\u0438\u0442\u043a\u043e';
var_dump(unescapeUTF8EscapeSeq($unicodeEncodedvalue));
echo "<br/>";
$json = '{
"email": "s2370@example.com",
"Hi": "\\u0416\\u0435\\u043d\\u044f",
"socials": {
"facebook": {
"identifier": "345",
"webSiteURL": "",
"profileURL": "https://www.facebook.com/app_scoped_user_id/345/",
"photoURL": "https://graph.facebook.com/345/picture?width=150&height=150",
"displayName": "Николай Решитко",
"description": "",
"firstName": "Николай",
"lastName": "Решитко",
"gender": "male",
"language": "ru_RU",
"age": null,
"birthDay": null,
"birthMonth": null,
"birthYear": null,
"email": "s2370@example.com",
"emailVerified": "s2370@example.com",
"phone": null,
"address": null,
"country": null,
"region": "",
"city": null,
"zip": null,
"username": "",
"coverInfoURL": "https://graph.facebook.com/345?fields=cover"
}
},
"time": "2015-10-13T09:30:44-04:00"
}';
echo "<pre>";
var_dump(json_decode($json, true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment