Share the 21 frequently used PHP function code segments (I) (1 ). The following describes the 21 function code segments that are frequently used in PHP Development. when we use them, we can use them directly. 1. PHP can read the random string. this code will create:
PHPThe 21 function code segments that are frequently used during development can be directly used when we use them.
1. PHP 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.
- /**************
- *@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. PHP generates a random string
If you do not need readable strings, use this function instead to create a random string as your random password.
- /*************
- *@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. PHP-encoded email address
This code can be used to encode any email address as an html character entity to prevent being collected by spam programs.
- 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 ='