PHP and c#: How to generate alphanumeric id for web content?
I want a script in PHP and c# which will generate id's like the following sites are doing:
Youtube http://www.yout开发者_如何学运维ube.com/watch?v=OdAE3cWlmHw
is doing it like OdAE3cWlmHw
Bit.ly http://bit.ly/2pUswX
doing it like 2pUswX
What will be the function to generate such type of unique id's in PHP and c#?
Create an array (or string) holding the characters A-Z and numbers 0-9. Then write a loop that runs for the number of characters you want in your ID - e.g. 10 - for ($i = 0; $i < 10; $i++)
In that loop, get a random number between 0 and the length of your array/string holding A-Z, 0-9, look up the character at that position in the array/string and append it to your ID string.
This logic is the same for both PHP and C#, just the language syntax will be different.
There is some codeproject code you can take a look at for the C# side of things here:
http://www.codeproject.com/KB/database/Alphanumaric_incriment.aspx?msg=1983998
If you are familiar with both PHP and C#, this will hopefully answer your question.
精彩评论