PHP practical code collection. 1. readable random string this code creates a readable string that is closer to the word in the dictionary and has a password verification function. Copy the code as follows: ***** 1. you can read random strings.
This code creates a readable string that is closer to a word in the dictionary and is practical and password-verified.
The code is as follows:
/**************
* @ Length-length of random string (must be a multiple of 2)
**************/
Function readable_random_string ($ length = 6 ){
$ Conso = array ("B", "c", "d", "f", "g", "h", "j", "k ", "l ",
"M", "n", "p", "r", "s", "t", "v", "w", "x", "y ", "z ");
$ Vocal = array ("a", "e", "I", "o", "u ");
$ Password = "";
Srand (double) microtime () * 1000000 );
$ Max = $ length/2;
For ($ I = 1; $ I <= $ max; $ I ++)
{
$ Password. = $ conso [rand (0, 19)];
$ Password. = $ vocal [rand (0, 4)];
}
Return $ password;
}
2. Generate a random string
If you do not need readable strings, use this function instead to create a random string as your random password.
The code is as follows:
/*************
* @ L-length of random string
*/
Function generate_rand ($ l ){
$ C = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
Srand (double) microtime () * 1000000 );
For ($ I = 0; $ I <$ l; $ I ++ ){
$ Rand. = $ c [rand () % strlen ($ c)];
}
Return $ rand;
}
3. encode the email address
This code can be used to encode any email address as an HTML character entity to prevent being collected by spam programs.
The code is as follows:
Function encode_email ($ email = 'info @ domain.com ', $ linkText = 'contact us', $ attrs = 'class = "emailencoder "')
{
// Remplazar aroba y puntos
$ Email = str_replace ('@', '@', $ email );
$ Email = str_replace ('.', '.', $ email );
$ Email = str_split ($ email, 5 );
$ LinkText = str_replace ('@', '@', $ linkText );
$ LinkText = str_replace ('.', '.', $ linkText );
$ LinkText = str_split ($ linkText, 5 );
$ Part1 = '$ part2 = 'ilto :';
$ Part3 = '"'. $ attrs. '> ';
$ Part4 = '';
$ Encoded ='