note 83321 added to function.md5

From: Date: Tue, 20 May 2008 22:19:53 +0000
Subject: note 83321 added to function.md5
Groups: php.notes 
Request: Send a blank email to php-notes+get-139565@lists.php.net to get a copy of this message
To convert an MD5 to 22 chars that contains only letters and numeric <?php define('HEX_CHARS', '0123456789abcdef'); define('BASE62_CHARS', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); /*********************************************/ function ConvertFromArbitraryBase($Str, $Chars) /*********************************************/ { /* Converts from an arbitrary-base string to a decimal string */ if (ereg('^[' . $Chars . ']+$', $Str)) { $Result = '0'; for ($i=0; $i<strlen($Str); $i++) { if ($i != 0) $Result = bcmul($Result, strlen($Chars)); $Result = bcadd($Result, strpos($Chars, $Str[$i])); } return $Result; } return false; } /*******************************************/ function ConvertToArbitraryBase($Str, $Chars) /*******************************************/ { /* Converts from a decimal string to an arbitrary-base string */ if (ereg('^[0-9]+$', $Str)) { $Result = ''; do { $Result .= $Chars[bcmod($Str, strlen($Chars))]; $Str = bcdiv($Str, strlen($Chars)); } while (bccomp($Str, '0') != 0); return strrev($Result); } return false; } /**********************/ function CustomMD5($Str) /**********************/ { return ConvertToArbitraryBase(ConvertFromArbitraryBase(md5($Str), HEX_CHARS), BASE62_CHARS); } ?> ---- Server IP: 82.80.248.162 Probable Submitter: 89.139.75.5 ---- Manual Page -- http://www.php.net/manual/en/function.md5.php Edit -- https://master.php.net/note/edit/83321 Del: integrated -- https://master.php.net/note/delete/83321/integrated Del: useless -- https://master.php.net/note/delete/83321/useless Del: bad code -- https://master.php.net/note/delete/83321/bad+code Del: spam -- https://master.php.net/note/delete/83321/spam Del: non-english -- https://master.php.net/note/delete/83321/non-english Del: in docs -- https://master.php.net/note/delete/83321/in+docs Del: other reasons-- https://master.php.net/note/delete/83321 Reject -- https://master.php.net/note/reject/83321 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139565) next »