- substr: documentation ( source)
- mt_rand: documentation ( source)
<?php
function genPass($length) {
$allowed = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWXYZ!£$%^&*()';
$password = '';
while(strlen($password) < $length) {
$password .= substr(mt_rand(0,strlen($allowed)), $allowed, 1);
}
return $password;
}
echo genPass(16);