Chaîne aléatoire en PHP
November 15, 2009
Ça sert toujours, une fonction pour générer une chaîne aléatoire :
function randStr($len, $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
$as = strlen($alphabet) - 1;
$str = "";
for($i = 0; $i < $len; $i++) {
$str .= $alphabet[rand(0, $as)];
}
return $str;
}
Filed under: PHP,Programmation,Trucs et astuces
Leave a Comment
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
RSS feed for comments on this post.