php-unicode/lib/unicode.php

43 lines
950 B
PHP
Raw Normal View History

2016-03-16 23:11:31 +00:00
<?php
class UnicodeShim
{
public static function bind()
{
static $init;
if ($init++) return;
function uchr($ord)
{
return json_decode('"'.'\u'.dechex($ord).'"');
}
2016-10-30 12:19:31 +00:00
function U($ord)
{
return uchr($ord);
}
2016-03-16 23:11:31 +00:00
function uprintf($arg)
{
$str = call_user_func_array('sprintf', func_get_args());
$str = preg_replace_callback("/(\\\\u[0-9a-f]{1,4})/i", function ($chr) {
return json_decode('"'.$chr[1].'"');
}, $str);
echo $str;
}
function usprintf($arg)
{
$str = call_user_func_array('sprintf', func_get_args());
$str = preg_replace_callback("/(\\\\u[0-9a-f]{1,4})/i", function ($chr) {
return json_decode('"'.$chr[1].'"');
}, $str);
return $str;
}
}
}
UnicodeShim::bind();