« Back to the tutorial

Demo: Generate random string of characters in PHP

Refresh to see function working!

Lowercase: echo random_string('lower',20);
stfhfchjekfxunukuqbw

Uppercase: echo random_string('upper',20);
KIMWKONRQFKVMPYUZCYK

Numbers: echo random_string('numbers',10);
3929747571

Special chars: echo random_string('special',40);
)@?*(+!+(*@!@?)*?*+)-+-?)(-)*%(-+@*(!+!?

All defined chars: echo random_string('all',50);
r)ih-s65@?d@(@vplk1*%!gdl^+03+g1+o978tqxtnpk06v!kn