Skip to content

Instantly share code, notes, and snippets.

@rduarte
rduarte / base62.php
Created April 2, 2009 22:34
base62 algorithm - encode and decode
<?php
function base62_encode($num){
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$base = 62;
$result = '';
while($num >= $base) {
$r = $num%$base;
$result = $chars[$r].$result;
$num = $num/$base;