Last active
August 29, 2015 14:18
-
-
Save jstxx/11906e19cddee96cb074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function unicode_decode ( $string ) | |
{ | |
function decode_unicode ( $c ) | |
{ | |
return ( ( $c = ( isset ( $c[3] ) ? $c[3] | |
: | |
( isset ( $c[2] ) ? hexdec ( $c[2] ) | |
: | |
hexdec ( $c[1] ) ) ) ) < 0x80 ? chr ( $c ) | |
: | |
( $c < 0x800 ? chr ( 0xc0 | ( $c >> 6 ) ) . chr ( 0x80 | ( $c & 0x3f ) ) | |
: | |
( $c < 0x10000 ? chr ( 0xe0 | ( $c >> 12 ) ) . chr ( 0x80 | ( ( $c >> 6 ) & 0x3f ) ) . chr ( 0x80 | ( $c & 0x3f ) ) | |
: | |
( $c < 0x200000 ? chr ( 0xf0 | ( $c >> 18 ) ) . chr ( 0x80 | ( ( $c >> 12 ) & 0x3f ) ) . chr ( 0x80 | ( ( $c >> 6 ) & 0x3f ) ) . chr ( 0x80 | ( $c & 0x3f ) ) : '' ) ) ) | |
); | |
} | |
return preg_replace_callback ( '~(?:\\\\\\u|%u)([0-9a-f]{4})|�*([0-9a-f]+);|�*([0-9]+);~i', 'decode_unicode', $string ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment