random alphanumeric text of length $codelength


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2. returns a random alphanumeric text of length $codelength (defaults to 4 characters)
  3. usage echo random_text(); or $output = random_text();
  4. 48 to 57 are the numbers
  5. 65 to 90 are UpperCase
  6. 97 to 122 are LowerCase
  7. */
  8. function random_text($code_length = 4){
  9. for($code_length, $newcode = ''; strlen($newcode) < $code_length; $newcode .= chr(!rand(0, 2) ? rand(48, 57) : (!rand(0, 1) ? rand(65, 90) : rand(97, 122))));
  10. return $newcode;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.