Generate Random String PHP Source Code

2016-07-04T22:48:01+08:00

Generate Random String PHP Source Code can be very useful in lot of situations. You will generate random passwords, a approval requirements and so on. The details in Generate Random String PHP Source Code are the followings: Define the legitimate characters can be used in the string Define the duration of the string Generating a random number Generate Random String PHP Source Code function getRandomString($length = 6) { $validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ+-*#&@!?"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } echo getRandomString();