note 70307 added to function.md5

From: Date: Wed, 11 Oct 2006 05:01:10 +0000
Subject: note 70307 added to function.md5
Groups: php.notes 
Request: Send a blank email to php-notes+get-118385@lists.php.net to get a copy of this message
Regarding the md5_base64 function posted below, since the encoded string will never be longer than 64 characters (the maximum length of a base64 encoded line), and the fact that base64 strings only insert the '=' pad character at the end of an encoded line, instead of using preg_replace, you can just use rtrim. $myhash=rtrim(base64_encode(pack("H*",md5($data))),"="); This will result in a string of 22 characters, suitable for inserting in mysql or whatever. Also, if you are testing against the string in a query in mysql, make sure to use the keyword BINARY, as case matters. The reason for the function in the first place (for me): If you're currently using an md5 hash for a unique index, this will save at least 20 bytes for every record on disk (index + data) and 10 bytes in memory. If you have millions of rows, that can really add up (100 million rows would require about 1 less gigabyte of memory for your key_buffer_size variable in mysql). ---- Server IP: 216.194.113.175 Probable Submitter: 66.188.26.156 ---- Manual Page -- http://www.php.net/manual/en/function.md5.php Edit -- https://master.php.net/note/edit/70307 Del: integrated -- https://master.php.net/note/delete/70307/integrated Del: useless -- https://master.php.net/note/delete/70307/useless Del: bad code -- https://master.php.net/note/delete/70307/bad+code Del: spam -- https://master.php.net/note/delete/70307/spam Del: non-english -- https://master.php.net/note/delete/70307/non-english Del: in docs -- https://master.php.net/note/delete/70307/in+docs Del: other reasons-- https://master.php.net/note/delete/70307 Reject -- https://master.php.net/note/reject/70307 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118385) next »