random_string([$type = 'alnum'[, $len = 8]])
Parameters: |
|
---|---|
Returns: |
A random string |
Return type: |
string |
Generates a random string based on the type and length you specify. Useful for creating passwords or generating random hashes.
The first parameter specifies the type of string, the second parameter specifies the length. The following choices are available:
- alpha: A string with lower and uppercase letters only.
- alnum: Alpha-numeric string with lower and uppercase characters.
-
basic: A random number based on
mt_rand()
. - numeric: Numeric string.
- nozero: Numeric string with no zeros.
-
md5: An encrypted random number based on
md5()
(fixed length of 32). -
sha1: An encrypted random number based on
sha1()
(fixed length of 40).
Usage example:
echo random_string('alnum', 16);
Note
Usage of the unique and encrypt types is DEPRECATED. They are just aliases for md5 and sha1 respectively.
Please login to continue.