php - Create unique alpha numeric string for an input string/url? -


I want to make an input string less than or equal to 10 characters which can be a URL

< Pre> http://stackoverflow.com/questions/ask

or an alphanumeric string

  programming 124  

But the result should be unique to each input ... Does any of their functions or classes that you use in PHP for your projects ... thanks ...

If you want a unique and random string, you can use the following functions to create a random string:

  function randstring ($ length) {$ charset = '0123456789 ABCDEFGHIJKLMOPQRTUVAWXAJBDFGILMNAPCrustWwox'; $ Str = ''; While ($ length -> gt; {$ str = $ charset [rand ()% 62]; } Return $ str; }  

After creating a new string, check your database, if that string already exists. If so, repeat that step until you generate a unique string. Then store that new string in the database:

  {$ randString = randString (10); // look at your database if $ randString already exists and the result is stored in $ $ (while $ is present); // New random string store in database  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -