- 相關(guān)推薦
最實用的PHP實例代碼21個
PHP 是一種 HTML 內(nèi)嵌式的語言,是一種在服務器端執(zhí)行的嵌入HTML文檔的腳本語言,語言的風格有類似于C語言,被廣泛的運用。以下是百分網(wǎng)小編搜索整理的關(guān)于最實用的PHP實例代碼21個,供參考借鑒,希望對大家有所幫助!想了解更多相關(guān)信息請持續(xù)關(guān)注我們應屆畢業(yè)生考試網(wǎng)!
1. PHP可閱讀隨機字符串
此代碼將創(chuàng)建一個可閱讀的字符串,使其更接近詞典中的單詞,實用且具有密碼驗證功能。
/**************
*@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生成一個隨機字符串
如果不需要可閱讀的字符串,使用此函數(shù)替代,即可創(chuàng)建一個隨機字符串,作為用戶的隨機密碼等。
/*************
*@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編碼電子郵件地址
使用此代碼,可以將任何電子郵件地址編碼為 html 字符實體,以防止被垃圾郵件程序收集。
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 = ’’;
$part4 = ’’;
$encoded = ’
script 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.write(’$l’);";
}
$encoded .= "document.write(’$part4’);";
$encoded .= ’/script
【最PHP實例代碼21個】相關(guān)文章:
PHP實用的代碼實例08-12
實用的PHP實例代碼20個06-11
PHP中檢測ajax請求的代碼實例10-25
php中使用redis隊列操作實例代碼05-16
php獲取新浪微博數(shù)據(jù)API的實例代碼08-06
PHP中獎概率的抽獎算法程序代碼實例08-05
php畫圖實例07-16
PHP調(diào)用的C代碼08-05
php語言字典代碼06-08