Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Create a random string of x characters using defined string of possible characters

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 107
    Comment on it

    To create a random string of x characters using defined string of possible characters we will first of all define a function which will return a random string of length that you have passed as a parameter to the function. The script is given below:

    <?php
    function randomStr($len) { 
       srand(date("s")); 
       $possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()"; 
       $str=""; 
       while(strlen($str)<$len) { 
          $str.=substr($possible,(rand()%(strlen($possible))),1); 
       } 
       return($str); 
    } 
    
    echo randomStr(8); //calling the function which will generate a random string of 8 characters.
    ?>
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: