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

, (Hidden)

*

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.


Calendar

February 2012
M T W T F S S
« Oct    
 12345
6789101112
13141516171819
20212223242526
272829  

Recent Posts