/ Published in: PHP

Function for generating random strings
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function rndstr($length=11, $type='a-zA-Z0-9') { $return = $chars = null; $chars .= 'abcdefghijklmnopqrstuvwxyz'; $chars .= 'ABCDEFGHIJKLMNOPRQSTUVWXYZ'; $chars .= '0123456789'; return $return; } /** **** Examples **** --- We need alphanumeric string 5 chars length --- echo rndstr(5); --- We need lowercase letters string 10 chars length --- echo rndstr(10, 'a-z'); --- We need lower and upper case letters string 10 chars length --- echo rndstr(10, 'A-Za-z'); --- We need numeric string 10 chars length --- echo rndstr(10, '0-9'); --- ect.. --- **/
Comments
