fork(1) download
  1. <?php
  2.  
  3. /**
  4.  * md5()等が生成する16進文字列を受け取り
  5.  * 短縮url用の独自の64進文字列にする
  6. **/
  7. function sr_hex2s64($hex) {
  8. $char_table = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM-_";
  9. $tablelen = strlen($char_table);
  10.  
  11. $output = "";
  12. $cut = 6;
  13. $hex = strrev($hex);
  14.  
  15. while(strlen($hex) > 0) {
  16. $dec = hexdec( strrev(substr($hex,0,$cut)) ) ;
  17.  
  18. $dec = ((int)($dec / 4096)) xor ($dec % 4096);
  19.  
  20. while( $dec > 0 ) {
  21. $cnum = $dec % $tablelen;
  22. $output .= $char_table[$cnum];
  23. $dec = (($dec - $cnum) / $tablelen);
  24. }
  25. $hex = substr($hex,$cut);
  26. }
  27. return $output;
  28. }
  29.  
  30. echo sr_hex2s64(md5("a unique data"));
  31. ?>
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
DQWplOHek6