For instance
http://www.youtube.com/watch?v=NVt4jOasujc
Such as 'NVt4jOasujc' instead of a regularly used integer ID.
Is it generated randomly or there is a special algorithm like having a connect with the auto increased ID?
How to generate a youtube like video unique ID
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: How to generate a youtube like video unique ID
PHP has a built-in unique random number generator, which is really good as it ensures a unique number as it is based on the micro unix time stamp.
$unique_number = uniqid(rand(), true);
Hope this helps
$unique_number = uniqid(rand(), true);
Hope this helps
Re: How to generate a youtube like video unique ID
Or you could create a recursive function.. probably not recommended, but it's what I do.
Code: Select all
function genRandId()
{
$chars = array_merge(range('A', 'Z'), range(0, 9), array('-', '_'));
shuffle($chars)
$randid = $chars[0] . $chars[1] . $chars[2] . $chars[3] . $chars[4] . $chars[5] . $chars[6];
if ($thisRandIdAlreadyExistsInDatabase)
{
genRandId();
}
return $randid;
}
echo genRandId();Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.