Skip to content

Commit

Permalink
Added polyfill for mb_ord
Browse files Browse the repository at this point in the history
  • Loading branch information
carbontwelve committed Feb 13, 2018
1 parent 023cc34 commit 2825548
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
"autoload": {
"psr-4": {
"Photogabble\\ConfusableHomoglyphs\\": "src/"
}
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
22 changes: 22 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Polyfill for mb_ord on PHP versions < 7.2
*/
if (!function_exists('mb_ord')) {
/**
* @author John Slegers
* @see https://stackoverflow.com/a/24763271/1225977
* @param string $char
* @param string $encoding
* @return mixed
*/
function mb_ord($char, $encoding = 'UTF-8') {
if ($encoding === 'UCS-4BE') {
list(, $ord) = (strlen($char) === 4) ? @unpack('N', $char) : @unpack('n', $char);
return $ord;
} else {
return mb_ord(mb_convert_encoding($char, 'UCS-4BE', $encoding), 'UCS-4BE');
}
}
}

0 comments on commit 2825548

Please sign in to comment.