- substr: documentation ( source)
- mt_rand: documentation ( source)
<?php
$n = 38;
$c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890-_';
for ($x=$s=0; $x<$n; $x++) {
$c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890';
if (($x<$n) && ($x > 0) && ($s < 2)) { $c .= '-_'; }
$r .= substr($c, mt_rand(0, strlen($c) - 1), 1);
if (($r == '_') || ($r == '-')) { $s++; }
}
echo $r;