PHP Classes

Bijection URL shortening: Encode and decode values for short URLs

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 403 All time: 6,547 This week: 39Up
Version License PHP version Categories
bijection 1.1Artistic License5.0PHP 5, Libraries, Code Generation
Description 

Author

This class can encode and decode values for short URLs.

It can take a given id number for a short URL that will eventually be stored in a database and generates a sequence of random characters that will be used to associate to the short URL of the given id.

The generated short URL may have an optional check digit.

The class can also that a previously generated short URL and decode it to find the original identifier number or the URL.

Innovation Award
PHP Programming Innovation award nominee
September 2015
Number 9
URL shortening services are very popular. Usually they store in a database a long URL that corresponds to a short character sequence.

This class implements an algorithm that makes the short URL character sequence be derived by a number that can be the id of the database record stored in a database.

This fact allows saving an additional field that would otherwise be used to store the short URL key.

The use of a check digit allows doing prior validation of short URLs without performing a database lookup.

These details make this algorithm more efficient than the traditional ways used to map short to long URLs.

Manuel Lemos
Picture of Zhao
  Performance   Level  
Name: Zhao <contact>
Classes: 3 packages by
Country: Japan Japan
Age: 48
All time rank: 22849 in Japan Japan
Week rank: 200 Up1 in Japan Japan Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

use rbib\util\string\encode\Bijection;

include
'rbib/util/string/encode/Bijection.php';

$bijection = (new Bijection());
//create short url based on int(100)
$encode_id = $bijection->encode(100);
echo
$encode_id; //aNbC

//decode the short url to int (100)
$decode_id = $bijection->decode($encode_id);
echo
$decode_id; //100



  Files folder image Files (2)  
File Role Description
Files folder imagerbib (1 directory)
Accessible without login Plain text file example.php Example demo for short url

  Files folder image Files (2)  /  rbib  
File Role Description
Files folder imageutil (1 directory)

  Files folder image Files (2)  /  rbib  /  util  
File Role Description
Files folder imagestring (1 directory)

  Files folder image Files (2)  /  rbib  /  util  /  string  
File Role Description
Files folder imageencode (1 file)

  Files folder image Files (2)  /  rbib  /  util  /  string  /  encode  
File Role Description
  Plain text file Bijection.php Class URL shortening algorithm

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:403
This week:0
All time:6,547
This week:39Up