0

I'm developing a URL shortener vyo.la, but I'm not sure exactly how to do exactly what I want. I've notcied that sites like bit.ly don't use integers, but some short of hash, hexadecimal or something simlar. My app, at this current time only uses integers. I've tried base64, but I've noticed it only encodes strings and converting the integer into a string provides a longer key than the integer itself.

Anyway to have a conversion using all uppercase and lowercase letters with digits so I can maximize the number of short URLs available?

I would prefer to have an easy conversion of the integer to value and value back to integer. I don't want to have a random friendly_id assigned to it to avoid collisions.

4

1 に答える 1

1

私が間違っていなければ、多くの URL 短縮サービスは base 36 (az、0-9) または 58 (az、AZ、0-9) を使用しています。これは base 58 の ruby​​ ライブラリです。readme の例から、探しているものになるはずです。

# Int to Base58
Base58.encode(12345) # => 4ER

# Base58 to Int
Base58.decode('A2Ph') # => 6639914
于 2012-08-09T20:40:24.097 に答える