Du bist hier: Snippet-Verzeichnis » PHP (128)
Sprache:

Base36, Base64 or Base16 functions in PHP

Sprache: English
Programmiersprache: PHP
Veröffentlicht von: shanx24 [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1647


Beschreibung

Base calculation functions implemented in PHP -- Base16, Base36 or Base64.

Code

1 <? 2 3 /** 4 * Function to calculate base36 values from a number 5 * 6 * @param $value The number 7 * @param $base The base to be applied (16, 36 or 64) 8 * @return The calculated string 9 * @author Shashank Tripathi (shanx@shanx.com) 10 * @version 0.1 - Let me know if something doesnt work 11 * 12 */ 13 14 function base36($value, $base) 15 { 16 $baseChars = array('0', '1', '2', '3', '4', '5', 17 '6', '7', '8', '9', 'a', 'b', 18 'c', 'd', 'e', 'f', 'g', 'h', 19 'i', 'j', 'k', 'l', 'm', 'n', 20 'o', 'p', 'q', 'r', 's', 't', 21 'u', 'v', 'w', 'x', 'y', 'z' 22 ); 23 24 $remainder = 0; 25 $newval = ""; 26 27 while ( $value > 0 ) 28 { 29 $remainder = $value % $base; 30 $value = ( ($value - $remainder)/ $base ); 31 $newval .= $baseChars[$remainder]; 32 } 33 return strrev($newval); 34 35 } 36 37 38 39 echo "The string for 46655, for instance, is " . base36(46655, 36); 40 41 ?>

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS