文档详情

二十一个实用便利的PHP代码摘录(Twenty-one practical handy PHP code extracts).doc

发布:2017-07-22约1.74万字共37页下载文档
文本预览下载声明
二十一个实用便利的PHP代码摘录(Twenty-one practical handy PHP code extracts) Twenty-one practical handy PHP code extracts 1. PHP can read random strings This code creates a readable string that makes it closer to the word in the dictionary, practical and has password authentication capabilities. /************** *@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 a readable string, instead of using this function, you can create a random string that serves as the users 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 encode email address With this code, you can encode any e-mail address into a HTML character entity to prevent collection by spam programs. Function, encode_email ($email=info@, $linkText=Contact, Us, $attrs, =class=, emailencoder) { Aroba y Puntos / / remplazar $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 =a href= Ma; $part2 =ilto:; $part3 = $attrs . ; $part4 =/a; $encodedscript type= = text/javascript ; $encoded = document.write ($part1);; $encoded = document.write ($part2);; Foreach ($email, as, $e) { $encoded = document.write ($e);; } $encoded = document.write ($part3);; Foreach ($linkText, as, $l) { $encoded = document.w
显示全部
相似文档