Merge pull request #145 from Alkarex/patch-1

smallHash: simplified and improved performance
This commit is contained in:
Sébastien SAUVAGE 2013-11-29 13:01:08 -08:00
commit ab0638edb0

View file

@ -221,7 +221,7 @@ function nl2br_escaped($html)
return str_replace('>','&gt;',str_replace('<','&lt;',nl2br($html))); return str_replace('>','&gt;',str_replace('<','&lt;',nl2br($html)));
} }
/* Returns the small hash of a string /* Returns the small hash of a string, using RFC 4648 base64url format
eg. smallHash('20111006_131924') --> yZH23w eg. smallHash('20111006_131924') --> yZH23w
Small hashes: Small hashes:
- are unique (well, as unique as crc32, at last) - are unique (well, as unique as crc32, at last)
@ -233,10 +233,7 @@ function nl2br_escaped($html)
function smallHash($text) function smallHash($text)
{ {
$t = rtrim(base64_encode(hash('crc32',$text,true)),'='); $t = rtrim(base64_encode(hash('crc32',$text,true)),'=');
$t = str_replace('+','-',$t); // Get rid of characters which need encoding in URLs. return strtr($t, '+/', '-_');
$t = str_replace('/','_',$t);
$t = str_replace('=','@',$t);
return $t;
} }
// In a string, converts urls to clickable links. // In a string, converts urls to clickable links.