Last active
May 25, 2018 14:10
-
-
Save kumirska/5034387ab1236a888ee85f03ee18a451 to your computer and use it in GitHub Desktop.
String to int encoder, decoder
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
<? | |
protected function strToInt($string) { | |
$unpacked = unpack('C*', $string); | |
return join( | |
array_map(function ($n) {return sprintf('%03d', $n);}, $unpacked) | |
); | |
} | |
protected function intToStr($number) { | |
$split = str_split($number, 3); | |
$mapped = array_map('chr', $split); | |
$joined = join($mapped); | |
return $joined; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment