- implode: documentation ( source)
- rand: documentation ( source)
<?php
function GeneratePassword ($length,$chars)
{
$res = array();
$char_length = strlen($chars) -1 ;
for($i = 0; $i < $length; $i++)
{
$res[] = $chars[rand(0,$char_length)];
}
return implode('', $res);
}
echo GeneratePassword(10, 'asdafdfgsaffhdhsd');