note 104912 deleted from function.rand by danbrown

From: Date: Fri, 15 Jul 2011 14:21:59 +0000
Subject: note 104912 deleted from function.rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181565@lists.php.net to get a copy of this message
Note Submitter: oxiroxt at gmail dot com ---- Based on adam at greatbigmassive dot com 02-Dec-2008 01:10 's use of preg_replace with eval idea This one-liner will generate a random string consisting of a-Z0-9, of as many characters long as printable characters you put in the 3th parameter of preg_replace: //This will return a 20 character long alphanumeric random string like: "v6Q0tdgI8lq4Fd0P8Pp4" preg_replace("/./e", "chr(array_rand(array_flip(array(rand(65,90),rand(97,122),rand(48,57))),1))", "...................."); Note: str_repeat won't work as it will only evaluate the random character once. If you know of a more simple alternative in the sorts of str_repeat, please email me and let me know, thanks! Regards, oxi

« previous php.notes (#181565) next »