Chaîne aléatoire en PHP

November 15th, 2009

Ça sert toujours, une fonction pour générer une chaîne aléatoire :

PHP:
  1. function randStr($len, $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
  2.     $as = strlen($alphabet) - 1;
  3.     $str = "";
  4.  
  5.     for($i = 0; $i <$len; $i++) {
  6.         $str .= $alphabet[rand(0, $as)];
  7.     }
  8.  
  9.     return $str;
  10. }

Entry Filed under: PHP, Programmation, Trucs et astuces

Leave a Comment

hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to the comments via RSS Feed


Calendar

September 2010
M T W T F S S
« Jun    
 12345
6789101112
13141516171819
20212223242526
27282930  

Most Recent Posts

Wikipedia Affiliate Button