Last active
July 9, 2018 16:49
-
-
Save qazd/6172f35c8a2452e8077c06a566895963 to your computer and use it in GitHub Desktop.
Converts each character of a text string to its hexadecimal representation from the Unicode code table. Forms a sequence delimited by space. Speed and efficiency were not tested.
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 | |
$string = 'è Ё𐐷-Xπ 🤔'; | |
foreach (preg_split('//u', $string) as $char) { | |
if (!$char) continue; | |
$hex = base_convert(mb_ord($char, 'UTF-8'), 10, 16); | |
$pad = strlen($hex) > 4 ? 8 : 4; | |
$hex = str_pad($hex, $pad, '0', STR_PAD_LEFT); | |
echo 'U+' . $hex . ' '; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment