aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlexandre Alapetite <alexandre@alapetite.fr>2013-11-10 22:50:34 +0100
committerAlexandre Alapetite <alexandre@alapetite.fr>2013-11-10 22:50:34 +0100
commitc002ca9c6ba1d40cda342ca85fb48acda39d7e52 (patch)
tree0342017dc7df2473d75274fb651dc76ef06838d8
parent7b2186a63e2c788f1f2622779c5a1c341117eac1 (diff)
downloadShaarli-c002ca9c6ba1d40cda342ca85fb48acda39d7e52.tar.gz
Shaarli-c002ca9c6ba1d40cda342ca85fb48acda39d7e52.tar.zst
Shaarli-c002ca9c6ba1d40cda342ca85fb48acda39d7e52.zip
smallHash: simplified and improved performance
Unchanged behaviour
-rw-r--r--index.php7
1 files changed, 2 insertions, 5 deletions
diff --git a/index.php b/index.php
index 0465a4e5..24fbe436 100644
--- a/index.php
+++ b/index.php
@@ -221,7 +221,7 @@ function nl2br_escaped($html)
221 return str_replace('>','&gt;',str_replace('<','&lt;',nl2br($html))); 221 return str_replace('>','&gt;',str_replace('<','&lt;',nl2br($html)));
222} 222}
223 223
224/* Returns the small hash of a string 224/* Returns the small hash of a string, using RFC 4648 base64url format
225 eg. smallHash('20111006_131924') --> yZH23w 225 eg. smallHash('20111006_131924') --> yZH23w
226 Small hashes: 226 Small hashes:
227 - are unique (well, as unique as crc32, at last) 227 - are unique (well, as unique as crc32, at last)
@@ -233,10 +233,7 @@ function nl2br_escaped($html)
233function smallHash($text) 233function smallHash($text)
234{ 234{
235 $t = rtrim(base64_encode(hash('crc32',$text,true)),'='); 235 $t = rtrim(base64_encode(hash('crc32',$text,true)),'=');
236 $t = str_replace('+','-',$t); // Get rid of characters which need encoding in URLs. 236 return strtr($t, '+/', '-_');
237 $t = str_replace('/','_',$t);
238 $t = str_replace('=','@',$t);
239 return $t;
240} 237}
241 238
242// In a string, converts urls to clickable links. 239// In a string, converts urls to clickable links.