[FLOW3-general] GUID shortener

Adrian Föder afoeder at live.de
Fri Mar 16 10:16:36 CET 2012


Hi List,

the idea is quickly explained: what do you think about a GUID shortener? 
The Identifier could be used across GET requests and does look pretty 
long, although of course with every use there's a bit overhead.

A simple fact is, that a GUID consists only of hexable values, while a 
URL may contain many more chars.
My first thought is based on a base64_encode implementation, see [1] for 
a sample; this is the code:

<?php
function ShortenGuid($guid) {
	$hexArray = str_split(str_replace('-', '', $guid), 2);
	$return = '';
	foreach ($hexArray AS $hexValue) {
		$return .= chr(hexdec($hexValue));
	}
	
	$return = base64_encode($return);
	$return = str_replace('+', '_', $return);
	$return = str_replace('/', '-', $return);
	$return = str_replace('=', '', $return);
	
	return $return;
}
echo ShortenGuid('27f20fd5-342b-4f9b-8d61-56f138fc1da9');
echo "\n";
echo ShortenGuid('8bfddf6f-610a-414d-8685-09cb6e54bf80');
echo "\n";
echo ShortenGuid('ed6519ed-d410-41ab-a29e-cdc03357b776');
?>

this outputs
 >>
J-IP1TQrT5uNYVbxOPwdqQ
i-3fb2EKQU2GhQnLblS-gA
7WUZ7dQQQauins3AM1e3dg
<<

This is imho not the best possible solution because as we all know 
base64_encode also has some overhead and does not use the full possible 
character range that may be used in URLs.

What do you think :)

Best,
Adrian

[1] http://codepad.org/1xtX5xrn


More information about the FLOW3-general mailing list