Skip to content

Instantly share code, notes, and snippets.

@inazt
Created July 23, 2010 21:40
Show Gist options
  • Save inazt/488078 to your computer and use it in GitHub Desktop.
Save inazt/488078 to your computer and use it in GitHub Desktop.
url-shorten-hash-generator
<?php
function getHash() {
$base=1000000;
$result = db_query_range('SELECT max(nid)+1 as nextId from {personal}', 0, 1);
$offset= db_fetch_object($result)->nextId;
$number=$base+$offset;
$out = "";
$codes = "abcdefghjkmnpqrstuvwxyz23456789ABCDEFGHJKMNPQRSTUVWXYZ";
while ($number > 53) {
$key = $number % 54;
$number = floor($number / 54) - 1;
$out = $codes{$key}.$out;
}
return $codes{$number}.$out;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment