项目作者: hamidgh83

项目描述 :
URL shortener Base-X encoder/decoder
高级语言: PHP
项目地址: git://github.com/hamidgh83/url_shortner.git
创建时间: 2019-10-08T06:40:18Z
项目社区:https://github.com/hamidgh83/url_shortner

开源协议:

下载


The package

Latest Stable Version
Total Downloads
Dependents
License

URL shortener Base-X encoder/decoder

This is a general purpose library to encode/decode an integer number. Given a string of valid alphabets you can encode your number into a small string.

A possible use case of this library is to use it as a url shortner. Just get the corresponding id of the url (from database) and encode it through this library. In this way you don’t need to store the hash value in the DB and you will be able to change your encryption algorithm at any time.

Possible use cases

  • Shorten URLs
  • Two way comunication
  • Hash generation

Examples

Example 1)

  1. $num = 98201564;
  2. $shotrner = new Shortner;
  3. $encodedStr = $shotrner->encode($num);
  4. echo $encodedStr;
  5. $decodedStr = $shotrner->decode($encodedStr);
  6. echo "\n" . $encodedStr;

Outputs:

  1. gOcSm
  2. 98201564

Example 2)

  1. $alphabets = "abcdefghijklmnopqrstuvwxyz";
  2. $num = 98201564;
  3. $shotrner = new Shortner($alphabets);
  4. $encodedStr = $shotrner->encode($num);
  5. echo $encodedStr;
  6. $decodedStr = $shotrner->decode($encodedStr);
  7. echo "\n" . $encodedStr;

Outputs:

  1. igxgpg
  2. 98201564