Created
October 31, 2020 16:56
-
-
Save AlekVolsk/20d0c0f016976de02e571fec3dbfe24c to your computer and use it in GitHub Desktop.
mb_ord() && mb_chr() for php < 7.2
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 | |
if (!function_exists('mb_ord')) { | |
function mb_ord($string) | |
{ | |
if (extension_loaded('mbstring') === true) { | |
mb_language('Neutral'); | |
mb_internal_encoding('UTF-8'); | |
mb_detect_order(array('UTF-8', 'ISO-8859-15', 'ISO-8859-1', 'ASCII')); | |
$result = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8')); | |
if (is_array($result) === true) { | |
return $result[1]; | |
} | |
} | |
return ord($string); | |
} | |
} | |
if (!function_exists('mb_chr')) { | |
function mb_html_entity_decode($string) | |
{ | |
if (extension_loaded('mbstring') === true) { | |
mb_language('Neutral'); | |
mb_internal_encoding('UTF-8'); | |
mb_detect_order(array('UTF-8', 'ISO-8859-15', 'ISO-8859-1', 'ASCII')); | |
return mb_convert_encoding($string, 'UTF-8', 'HTML-ENTITIES'); | |
} | |
return html_entity_decode($string, ENT_COMPAT, 'UTF-8'); | |
} | |
function mb_chr($string) | |
{ | |
return mb_html_entity_decode('&#' . intval($string) . ';'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment