- substr: documentation ( source)
- mt_rand: documentation ( source)
<?php
$long=20;
$caractères = 'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN0123456789éèùçà?&€@+-_()=:.*';
$string = '';
for($i=0 ; $i<$long ; $i++)
$string .= substr($caractères, (mt_rand() % strlen($caractères)), 1);
echo $string;
?>