Created
October 29, 2010 05:33
-
-
Save dervn/652979 to your computer and use it in GitHub Desktop.
tinyurl
This file contains 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
public static function shorturl($input) | |
{ | |
$base32 = array ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5' ); | |
$hex = md5($input); | |
$hexLen = strlen($hex); | |
$subHexLen = $hexLen / 8; | |
$output = array(); | |
for ($i = 0; $i < $subHexLen; $i++) | |
{ | |
$subHex = substr ($hex, $i * 8, 8); | |
$int = 0x3FFFFFFF & (1 * ('0x'.$subHex)); | |
$out = ''; | |
for ($j = 0; | |
$j < 5; $j++) | |
{ | |
$val = 0x0000001F & $int; | |
$out .= $base32[$val]; | |
$int = $int >> 5; | |
} | |
$output[] = $out; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment