Posted By

wyattstorch42 on 01/01/14


Tagged

php random String mtrandstr


Versions (?)

PHP Random String Function


 / Published in: PHP
 

Generates a random string of a given length and character set.

  1. <?php
  2. /**
  3.  * Generates a random string of a given length and character set.
  4.  * @param int $l The length of the resulting string
  5.  * @param string $c The character set
  6.  * @return string The random sequence
  7.  */
  8. function mt_rand_str ($l, $c = 'abcdefghijklmnopqrstuvwxyz1234567890') {
  9. for ($s = '', $cl = mb_strlen($c)-1, $i = 0; $i < $l; $s .= mb_substr($c, mt_rand(0, $cl), 1), ++$i);
  10. return $s;
  11. }
  12. ?>

Report this snippet  

You need to login to post a comment.