You are here

function shurly_dec2any in ShURLy 6

Same name and namespace in other branches
  1. 8 shurly.module \shurly_dec2any()
  2. 7 shurly.module \shurly_dec2any()

From http://www.php.net/manual/en/function.base-convert.php#52450

Parameters: $num - your decimal integer $base - base to which you wish to convert $num (leave it 0 if you are providing $index or omit if you're using default (62)) $index - if you wish to use the default list of digits (0-1a-zA-Z), omit this option, otherwise provide a string (ex.: "zyxwvu")

1 call to shurly_dec2any()
shurly_next_url in ./shurly.module
Return next available short URL

File

./shurly.module, line 319
description http://www.youtube.com/watch?v=Qo7qoonzTCE

Code

function shurly_dec2any($num, $base = 62, $index = FALSE) {
  if (!$base) {
    $base = strlen($index);
  }
  elseif (!$index) {

    // note: we could rearrange this string to get more random looking URLs
    // another note, to create printable URLs, omit the following characters: 01lIO
    $index = substr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, $base);
  }
  $out = "";
  for ($t = floor(log10($num) / log10($base)); $t >= 0; $t--) {
    $a = floor($num / pow($base, $t));
    $out = $out . substr($index, $a, 1);
    $num = $num - $a * pow($base, $t);
  }
  return $out;
}