diff options
author | Alexandre Alapetite <alexandre@alapetite.fr> | 2013-11-10 22:50:34 +0100 |
---|---|---|
committer | Alexandre Alapetite <alexandre@alapetite.fr> | 2013-11-10 22:50:34 +0100 |
commit | c002ca9c6ba1d40cda342ca85fb48acda39d7e52 (patch) | |
tree | 0342017dc7df2473d75274fb651dc76ef06838d8 /index.php | |
parent | 7b2186a63e2c788f1f2622779c5a1c341117eac1 (diff) | |
download | Shaarli-c002ca9c6ba1d40cda342ca85fb48acda39d7e52.tar.gz Shaarli-c002ca9c6ba1d40cda342ca85fb48acda39d7e52.tar.zst Shaarli-c002ca9c6ba1d40cda342ca85fb48acda39d7e52.zip |
smallHash: simplified and improved performance
Unchanged behaviour
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 7 |
1 files changed, 2 insertions, 5 deletions
@@ -221,7 +221,7 @@ function nl2br_escaped($html) | |||
221 | return str_replace('>','>',str_replace('<','<',nl2br($html))); | 221 | return str_replace('>','>',str_replace('<','<',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) | |||
233 | function smallHash($text) | 233 | function 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. |