note 112502 deleted from function.base-convert by tularis

From: Date: Mon, 24 Jun 2013 20:50:26 +0000
Subject: note 112502 deleted from function.base-convert by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195338@lists.php.net to get a copy of this message
Note Submitter: kexianbin at diyism dot com ---- <?php function my_base_convert($str, $from_base_chars, $to_base_chars) {$gmp_base_chars='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; $from_base_chars=is_int($from_base_chars)?substr($gmp_base_chars, 0, $from_base_chars):$from_base_chars; $to_base_chars=is_int($to_base_chars)?substr($gmp_base_chars, 0, $to_base_chars):$to_base_chars; $from_base=strlen($from_base_chars); $to_base=strlen($to_base_chars); if (strpos($gmp_base_chars, $from_base_chars)!==0) {$str=strtr($str, array_combine(str_split($from_base_chars), str_split(substr($gmp_base_chars, 0, $from_base)))); } $str=gmp_strval(gmp_init($str, $from_base), $to_base); if (strpos($gmp_base_chars, $to_base_chars)!==0) {$str=strtr($str, array_combine(str_split(substr($gmp_base_chars, 0, $to_base)), str_split($to_base_chars))); } return $str; } ?> example: <?php echo my_base_convert('FFD132A3', 16, 10); echo my_base_convert('FFD132A3', 16, 'ABCDEFGHIJKLM'); echo my_base_convert('1265537', '1234567', 58); ?>

« previous php.notes (#195338) next »