Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
/ 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

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.