- substr: documentation ( source)
- mt_rand: documentation ( source)
<?php
function multiID($n=32) {
for ($x=$s=0,$r=null; $x<$n; $x++) {
$c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890';
if (($x<$n) && ($x > 0) && ($s < 2)) { $c .= "\002D_"; }
$g = substr($c, mt_rand(0, strlen($c) - 1), 1);
$r .= $g;
if (($g == '_') || ($g == "\002D")) { $s++; }
}
return $r;
}
echo multiID(6);