note 104912 added to function.rand

From: Date: Fri, 15 Jul 2011 06:37:56 +0000
Subject: note 104912 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-181547@lists.php.net to get a copy of this message
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 ---- Server IP: 130.206.1.5 Probable Submitter: 79.157.90.250 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/104912 Del: integrated -- https://master.php.net/note/delete/104912/integrated Del: useless -- https://master.php.net/note/delete/104912/useless Del: bad code -- https://master.php.net/note/delete/104912/bad+code Del: spam -- https://master.php.net/note/delete/104912/spam Del: non-english -- https://master.php.net/note/delete/104912/non-english Del: in docs -- https://master.php.net/note/delete/104912/in+docs Del: other reasons-- https://master.php.net/note/delete/104912 Reject -- https://master.php.net/note/reject/104912 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181547) next »