Decode/encode JavaScript Unicode escape sequences (like \u0230) for PHP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
Anton Smirnov 11802e939a
Update badges
2 年之前
bin add development console with Psysh 3 年之前
lib remove use of json_last_error_msg 3 年之前
tests change flow in the last test 3 年之前
.gitignore start the library 3 年之前
.travis.yml Cache composer libs for Travis (fix) 2 年之前
LICENSE.txt add license.txt 3 年之前 Update badges 2 年之前
composer.json add development console with Psysh 3 年之前

Unicode Entities Conversion

Packagist Packagist Travis Code Climate

This library converts between UTF-8 and JavaScript Unicode escape characters, i.e. 'š' <=> '\u0161'


Add to your composer.json:

    "require": {
        "sandfoxme/unicode-entities": "*"


$s = \SandFoxMe\Misc\UnicodeEntites::decode("K\\u00f3dov\\u00e1n\\u00ed znak\\u016f");
print $s; // "Kódování znaků"

$s = \SandFoxMe\Misc\UnicodeEntites::encode("文字コード");
print $s; // "\u6587\u5b57\u30b3\u30fc\u30c9"

UnicodeEntites::encode returns ASCII string with all non-ASCII characters encoded in JavaScript Unicode notation.

It’s a dirty hack! You use json_encode()!

Yes it’s a hack :) But it’s working and well-tested one, see /tests/


The library is available as open source under the terms of the MIT License.