Subscribe to atik's Blog        RSS Feed
-----

Random String Generator in PHP

Icon Leave Comment
This time we will see how to code a function which will generate random string in php-

function random_string($n)
{
    $numbers=range(0,9);        //array of digits
    $letters=range("A","Z");    //array of uppercase characters
    $characters=array_merge($numbers,$letters);
    $characters=array_flip($characters);    //switching key-value of array elements

    $string='';

    for($i=0;$i<$n;$i++)
    {
        $string .= array_rand($characters);     //returns random key from array and adds to $string
    }

    return $string;
}

0 Comments On This Entry

 

September 2014

S M T W T F S
 123456
78910111213
14151617181920
21222324252627
2829 30     

Tags

Recent Entries

Recent Comments

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)