Skip to content

Instantly share code, notes, and snippets.

@felds
Last active December 20, 2015 02:29
Show Gist options
  • Select an option

  • Save felds/6056221 to your computer and use it in GitHub Desktop.

Select an option

Save felds/6056221 to your computer and use it in GitHub Desktop.
Convert anything to HTML entities (including unicodes.)
<?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