Advertisement
CPV

cadena_aleatoria

CPV
Jun 2nd, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php
  2. function cadena_aleatoria($longitud = 62, $caracteres = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
  3.     $return = FALSE;
  4.     if (!is_int($longitud) || $longitud < 0) {
  5.         $return = FALSE;
  6.     } else {
  7.         $caracteres_longitud = strlen($caracteres) - 1;
  8.         for ($i = 0; $i < $longitud; $i++) {
  9.             $return .= $caracteres[mt_rand(0, $caracteres_longitud)];
  10.         }
  11.     }
  12.     return $return;
  13. }
  14. echo cadena_aleatoria();
  15. echo "<br />";
  16. echo cadena_aleatoria(12,'*[]{}');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement