dbradbury Posted January 27, 2010 Share Posted January 27, 2010 how do i make a random string, with will contain letters and number but set to a length of about 15? Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/ Share on other sites More sharing options...
aebstract Posted January 27, 2010 Share Posted January 27, 2010 http://php.net/manual/en/function.rand.php The manual has awesome information, like this post: <?php // Generate a random character string function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890') { // Length of character list $chars_length = (strlen($chars) - 1); // Start our string $string = $chars{rand(0, $chars_length)}; // Generate random string for ($i = 1; $i < $length; $i = strlen($string)) { // Grab a random character from our list $r = $chars{rand(0, $chars_length)}; // Make sure the same two characters don't appear next to each other if ($r != $string{$i - 1}) $string .= $r; } // Return the string return $string; } ?> Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002488 Share on other sites More sharing options...
dbradbury Posted January 27, 2010 Author Share Posted January 27, 2010 thanks greatly!! Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002489 Share on other sites More sharing options...
jl5501 Posted January 27, 2010 Share Posted January 27, 2010 Last post is one way or $random_str = substr(uniqid('Z'),-15,15); Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002490 Share on other sites More sharing options...
dbradbury Posted January 27, 2010 Author Share Posted January 27, 2010 thanks, what does that do, can i get rid of capitals? Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002493 Share on other sites More sharing options...
jl5501 Posted January 27, 2010 Share Posted January 27, 2010 I think you will find it only uses lower case letters http://php.net/manual/en/function.uniqid.php Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002496 Share on other sites More sharing options...
dbradbury Posted January 27, 2010 Author Share Posted January 27, 2010 nope, it started with a Z lol Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002498 Share on other sites More sharing options...
dbradbury Posted January 27, 2010 Author Share Posted January 27, 2010 all i want it a 32 alphanumeric string that has no capitals in it Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002500 Share on other sites More sharing options...
dbradbury Posted January 27, 2010 Author Share Posted January 27, 2010 doesnt matter now, dont need it lol Link to comment https://forums.phpfreaks.com/topic/190009-php-how-do-you-make/#findComment-1002610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.