四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

10個實用的PHP代碼片段

關鍵詞高亮
復制代碼 代碼如下:
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', '<strong style="background-color:yellow">$1</strong>', $sString);
}

獲取你的Feedburner的用戶
復制代碼 代碼如下:
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/GetFeedData?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);
}

自動生成密碼
復制代碼 代碼如下:
function generatePassword($length=9, $strength=0) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength >= 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength >= 2) {
$vowels .= "AEUY";
}
if ($strength >= 4) {
$consonants .= '23456789';
}
if ($strength >= 8 ) {
$vowels .= '@#$%';
}
$password = '';
$alt = time() % 2;
for ($i = 0; $i < $length; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
} else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}

壓縮多個CSS文件
復制代碼 代碼如下:
header('Content-type: text/css');
ob_start("compress");
function compress($buffer) {
/* remove comments */
$buffer = preg_replace('!//*[^*]*/*+([^/][^*]*/*+)*/!', '', $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("/r/n", "/r", "/n", "/t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
/* your css files */
include('master.css');
include('typography.css');
include('grid.css');
include('print.css');
include('handheld.css');
ob_end_flush();

獲取短網址
復制代碼 代碼如下:
function getTinyUrl($url) {
return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
}

根據生日計算年齡
復制代碼 代碼如下:
function age($date){
$year_diff = '';
$time = strtotime($date);
if(FALSE === $time){
return '';
}
$date = date('Y-m-d', $time);
list($year,$month,$day) = explode("-",$date);
$year_diff = date("Y") 主站蜘蛛池模板: 李乃文电影| 湖北卫视在线直播| 口述公交车上| 晕车喝什么饮料能缓解| high heels| 成年奶妈| 白皮书电影| 转正意见评语| 胡渭康| 猫小帅三十六计| 小恩雅骑马舞蹈视频| 幼儿园老师锦旗赠言| 夫妻性生活视屏| 洪金宝电影| 潇湘影院| 漂亮阿姨 李恩美演的什么电影| 韩绛| 四虎图库| 蜘蛛网中的女孩| 第一次美国电影| 防冲撞应急处置预案| 意大利斜体| love 电影| 数控图纸| 林正英演的全部电影| 肖颖| 武装少女免费观看| 嫦娥奔月读后感50字| 钱月笙| 日本电影部长| 沙漠电影高清在线播放| 追诉电视剧| 香港之夜免费观看视频完整版| 甜蜜高潮 第一季 电视剧| 地下车库设计规范| 大海在呼唤| 韩国电影《甜性涩爱》| 女王的条件| karina hart| 天堂真的存在| 大红枣儿甜又香简谱|