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
преди 1 година
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 години
README.md Update badges преди 1 година
composer.json add development console with Psysh преди 3 години

README.md

Unicode Entities Conversion

Packagist Packagist Travis Code Climate

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

Installation

Add to your composer.json:

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

Usage

$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/

License

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