PHP Generate random string A-Z and 0-9 using PHP

PHP Generate random string A-Z and 0-9 using PHPPHP Generate random string A-Z and 0-9 using PHP

In this poat we will show you PHP Generate random string A-Z and 0-9, we find that generating a random string can be tedious, there seem to be so many ways to do this. we wrote this simple function to do the work, and it can be easily modified.

<?php
/*
* onlinecode Create a random string
* @author onlinecode <>
* @param $string_length length of string to create
* @return $random_string string
*/
function random_string($string_length = 6) {
$random_string = "";
$random_characters = array_merge(range('0','9'), range('A','Z'), range('a','z'));
$max = count($random_characters) - 1;
for ($i = 0; $i < $string_length; $i++)
{
$rand = mt_rand(0, $max);
$random_string .= $random_characters[$rand];
}
return $random_string;
}
// PHP Generate random string A-Z and 0-9
echo random_string(6);

we can remove any of the ranges in $random_characters (for example if you didn’t want uppercase letters delete the range(‘A’,’Z’)) or put in your own array of characters.

Hope this code and post will helped you for implement PHP Generate random string A-Z and 0-9 using PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

20  +    =  26

We accept paid advance and paid guest Posting on our Site : Contact US