10个实用的PHP代码片段
前端之家收集整理的这篇文章主要介绍了
10个实用的PHP代码片段,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
关键词高亮
<div class="codetitle"><a style="CURSOR: pointer" data="21302" class="copybut" id="copybut21302" onclick="doCopy('code21302')"> 代码如下:
<div class="codebody" id="code21302">
function highlight($sString,$aWords) {
if (!is_array ($aWords) || empty ($aWords) || !is_string ($sString)) {
return false;
}
$sWords = implode ('|',$aWords);
return preg_replace ('@\b('.$sWords.')\b@si','<h3 style="background-color:yellow">$1',$sString);
}
获取你的
Feedburner的
用户 <div class="codetitle">
<a style="CURSOR: pointer" data="13016" class="copybut" id="copybut13016" onclick="doCopy('code13016')"> 代码如下: <div class="codebody" id="code1
3016">
function get_average_readers($
Feed_id,$interval = 7){
$today = date('Y-m-d',strtotime("now"));
$ago = date('Y-m-d',strtotime("-".$interval." days"));
$
Feed_url="https://
Feedburner.google.com/api/awareness/1.0/Get
FeedData?uri=".$
Feed_id."&dates=".$ago.",".$today;
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_URL,$
Feed_url);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->
Feed->entry['circulation'];
$nb = 0;
foreach($xml->
Feed->children() as $circ){
$nb += $circ['circulation'];
}
return round($nb/$interval);
}