Skip to content

Instantly share code, notes, and snippets.

@kumirska
Last active May 25, 2018 14:10
Show Gist options
  • Save kumirska/5034387ab1236a888ee85f03ee18a451 to your computer and use it in GitHub Desktop.
Save kumirska/5034387ab1236a888ee85f03ee18a451 to your computer and use it in GitHub Desktop.
String to int encoder, decoder
<?
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