Maisonnette » The Meh!


Generate a unique ID 10 characters long - PHP

Posted in Scripts by The Meh! on the September 11th, 2008

A PHP function to generate a unique ID 10 characters long based on the current UNIX timestamp (10 digits).

<?php
function gen_uniqid() {
	$char[0] = "ABCDEFGHIJ";
	$char[1] = "KLMNPQRSTU";
	$char[2] = "VWXYZabcde";
	$char[3] = "fghijklmnp";
	$char[4] = "qrstuvwxyz";
	$char[5] = "0123456789";
	$arr = preg_split('//', time(), -1, PREG_SPLIT_NO_EMPTY);

	$uniqid = "";
	foreach($arr as $val) {
		$str = $char[rand(0,5)];
		$uniqid .= $str{$val};
	}

	return $uniqid;
}
echo gen_uniqid();
?>

Leave a Reply

You must be logged in to post a comment.