URL Shortener Generator.


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function str_inc($str, $pos = 0)
  2. {
  3. $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_';
  4. $charsmax = strlen($chars);
  5. $len = strlen($str);
  6. if($len == 0)
  7. {
  8. return $chars[0];
  9. }
  10. $strindex = $len - $pos - 1;
  11. if($strindex < 0)
  12. {
  13. return $chars[0] . $str;
  14. }
  15. $char = $str[$strindex];
  16. $charsindex = strpos($chars, $char);
  17. if($charsindex == $charsmax)
  18. {
  19. $str[$strindex] = $chars[0];
  20. return str_inc($str, $pos + 1);
  21. }else{
  22. $str[$strindex] = $chars[$charsindex + 1];
  23. return $str;
  24. }
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.