Create random strings in php

Often we need to create random strings in PHP. Like sometime if we are uploading an image then we rename that image and create some random string and put that string as image name.

Another example if we wanted to cerate a token then many times we need to create random string.

How to do that?

Here is code which creates random strings. I have written three functions to create the random string. So you can create three types of random string here.

  1. randomStringAlpha() : Creates random string of alpha bates.
  2. randomStringNum() : Creates random string of numbers.
  3. randomAlphaNumString() : Creates random string of alpha bates and numbers.

You also can define the length of the random string by changing the $length variable.

  ...  Read More

Share This: