PHP开发中常用的十个代码样例
发布时间:2020-12-12 21:19:28 所属栏目:PHP教程 来源:网络整理
导读:一、黑名单过滤 = $arr[$word]) return true; } } return false; } $file = ‘spam.txt‘; $str = ‘This string has cat,dog word‘; if(is_spam($str,$file)) echo ‘this is spam‘; else echo ‘this is not spam‘; ab:3 dog:3 cat:2 monkey:2 二、随机
一、黑名单过滤 = $arr[$word])
return true;
}
}
return false;
}
$file = ‘spam.txt‘;
$str = ‘This string has cat,dog word‘;
if(is_spam($str,$file))
echo ‘this is spam‘;
else
echo ‘this is not spam‘;
ab:3
dog:3
cat:2
monkey:2
二、随机颜色生成器 三、从网上下载文件 四、Alexa/Google Page Rank (.+?) ~im‘,$content,$matches)){
return $matches[2];
}else{
return FALSE;
}
break;
case ‘google‘:
$rank = explode(‘:‘,$content);
if($rank[2] != ‘‘)
return $rank[2];
else
return FALSE;
break;
default:
return FALSE;
break;
}
}
// Alexa Page Rank:
echo ‘Alexa Rank: ‘.page_rank(‘techug.com‘);
echo ‘ ‘;
// Google Page Rank
echo ‘Google Rank: ‘.page_rank(‘techug.com‘,‘google‘);
五、强制下载文件 0){
$row = mysql_fetch_array($sql);
// Set some headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($row[‘FileName‘]).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($row[‘FileName‘]));
@readfile($row[‘FileName‘]);
exit(0);
}else{
header("Location: /");
exit;
}
六、用Email显示用户的Gravator头像 ‘;七、用cURL获取RSS订阅数 八、时间差异计算 = $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] ‘ago‘ ";
}
九、截取图片 十、检查网站是否宕机 =200 && $httpcode<300) return true;
else return false;
}
if (Visit("http://www.google.com"))
echo "Website OK"."n";
else
echo "Website DOWN";
以上内容针对PHP开发中常用的十个代码样例做了总结,希望对大家有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |