/ Published in: PHP
Create short url easy by modifying integer to characters
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * CodeIgniter ShortURL Library * * Create and Translate ShortURL from integer ID * * @location Application/libraries * @package CodeIgniter * @author Khalid Adisendjaja < [email protected] > * @website http://khalidadisendjaja.web.id */ Class Shorturl { protected $codeset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; protected $prefix; function __construct(){} public function setPrefix($p) { $this->prefix = $p; } public function createURL($base_url,$id) { return $base_url.$this->intToKeyword($id); } public function getURL($base_redirect_url,$keyword) { if($id = $this->keywordToInt($keyword)){ return $base_redirect_url.$id; }else{ return null; } } public function intToKeyword($url_id) { $n = $url_id; $converted = ""; while ($n > 0) { } return $this->prefix ? $this->prefix.$converted : $converted; } public function keywordToInt($keyword) { if($this->prefix){ $keyword = $matches[1]; }else{ return null; } } $converted = $keyword; $c = 0; } return $c; } }