note 51957 added to function.mt-rand

From: Date: Sun, 17 Apr 2005 02:46:16 +0000
Subject: note 51957 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-88093@lists.php.net to get a copy of this message
An advanced Shell/PHP string generator - made for command line: #!/usr/bin/php -q <?php if( $argv[1] == null || $argv[1] <= 0 || !is_numeric($argv[1]) ) { $argv[1] = 10; } $limit = $argv[1]; if( $argv[2] == null ) { $use = array('l', 'u', 'n'); } else { $tmp = wordwrap($argv[2], 1, ':', true); $use = explode(':', strtolower($tmp)); } // USE $feed = array(''); // create array, to avoid any possible errors if( in_array('l', $use) ) { // lowercase characters [l=lowercase] $feed[] = 'abcdefghijklmnopqrstuvwxyz'; } if( in_array('u', $use) ) { // capital characters [u=uppercase] $feed[] = strtoupper('abcdefghijklmnopqrstuvwxyz'); } if( in_array('o', $use) ) { // 'other' characters [o=other] $feed[] = ' !@#$%^&*()-+=/\:;{}[]<>?'; } if( in_array('n', $use) ) { // numerical characters [n=numbers] $feed[] = '0123456789'; } // shuffle the array, appear more random - this is not necessary shuffle($feed); // store feed into a single string $feed = implode('', $feed); // loop through and do your stuff for ($i=0; $i < $limit; $i++) { echo substr($feed, mt_rand(0, strlen($feed)-1), 1); } // echo out a break :-) echo "\n"; ?> Usage: strgen [length/limit] [USE] Example #1: strgen 10 loun // eg. output: ?<ro3:Z$(A Example #2: strgen 32 ln // eg. output: gb9ed4w8ynrve08tj1n6zsux30enmjq2 Example #3: strgen 15 uo // eg. output: @*=:N^T?H>Z;MMV This little utility is great for password generation, it allows you to include or exclude the use of lowercase characters, capitcal characters, 'other' characters, and numbers "on the fly!" Have fun! ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51957 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51957&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51957&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51957&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51957&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51957&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51957&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88093) next »