#!/usr/bin/php 255) { $length = 255; } if ($length < 2) { $length = 2; } $alpha = range('0', '9'); $alpha = array_merge($alpha, array( '!', 'ยง', '$', '%', '&', '/', '(', ')', '=', '?' , '-', '_', '+', '#', '.', ',' )); $cntN = count($alpha); $alpha = array_merge($alpha, range('A', 'Z')); if (!$capitalOnly) { $alpha = array_merge($alpha, range('a', 'z')); } $cnt = count($alpha) - 1; $rc = array(); // force obscurce code to start with a letter if ($startLetter) { $rc[] = $alpha[rand($cntN, $cnt)]; --$length; } if ($endLetter) { --$length; } // fill with random letters and digists for ($i = 0; $i < $length; ++$i) { $rc[] = $alpha[rand(0, $cnt)]; } if ($endLetter) { $rc[] = $alpha[rand($cntN, $cnt)]; } return implode('', $rc); } } $maker = new PasswordMaker(); echo $maker->getRandom($length) . "\n";