note 23062 deleted from ref.math by cmb

From: Date: Sun, 21 Jul 2019 08:55:55 +0000
Subject: note 23062 deleted from ref.math by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211654@lists.php.net to get a copy of this message
Note Submitter: shanx at shanx dot com ---- <? /** * Function to calculate base36 values from a number. Very * useful if you wish to generate IDs from numbers. * * @param $value The number * @param $base The base to be applied (16, 36 or 64) * @return The calculated string * @author Shashank Tripathi (shanx@shanx.com) * @version 0.1 - Let me know if something doesnt work * */ function base36($value, $base) { $baseChars = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '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' ); $remainder = 0; $newval = ""; while ( $value > 0 ) { $remainder = $value % $base; $value = ( ($value - $remainder)/ $base ); $newval .= $baseChars[$remainder]; } return strrev($newval); } echo "The string for 46655, for instance, is " . base36(46655, 36); ?>

« previous php.notes (#211654) next »