Skip to content
/ Base Public

Library to convert decimals to base62 strings, useful for shortURLs based on ID numbers in a database.

Notifications You must be signed in to change notification settings

ServiceTo/Base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Base

Library to convert integers to base62 strings, useful for shortURLs based on ID numbers in a database.

Usage

Install using composer...

composer require "service-to/base"

In a Laravel Controller

Route::get('{shortcode}', function ($shortcode) {
	$base = new ServiceTo\Base();
	return View::make("content")->withArticle(App\Article::find($base->base2int($shortcode)));
});

In plain old PHP

require_once("vendor/autoload.php");
use ServiceTo\Base;

function shorturl($url) {
	$myshortdomain = "http://short.long.urls.3.14159.xyz/";

	$base = new Base();
	$stmt = $pdo->prepare("INSERT INTO shorturls SET url=?");
	$stmt->bindValue(1, $url, PDO::PARAM_STR);
	$stmt->execute();

	return($myshortdomain . $base->int2base($stmt->lastInsertId()));
}

About

Library to convert decimals to base62 strings, useful for shortURLs based on ID numbers in a database.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages