Last active
December 20, 2015 02:29
-
-
Save felds/6056221 to your computer and use it in GitHub Desktop.
Convert anything to HTML entities (including unicodes.)
This file contains hidden or 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 everythingEntities($str, $pattern = '/./u') | |
| { | |
| return preg_replace_callback($pattern, function ($match) { | |
| list(, $ord) = unpack('N', mb_convert_encoding($match[0], 'UCS-4BE', 'UTF-8')); | |
| return sprintf('&#%s;', $ord); | |
| }, $str); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment