php-unicode/lib/unicode.php

38 lines
873 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).'"');
}
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();