《PHP應用:PHP常用的小程序代碼段》要點:
本文介紹了PHP應用:PHP常用的小程序代碼段,希望對您有用。如果有疑問,可以聯系我們。
PHP應用本文實例講述了PHP常用的小程序代碼段.分享給大家供大家參考,具體如下:
PHP應用1.計算兩個時間的相差幾天
PHP應用
$startdate=strtotime("2009-12-09");
$enddate=strtotime("2009-12-05");
PHP應用上面的php時間日期函數strtotime已經把字符串日期變成了時間戳,這樣只要讓兩數值相減,然后把秒變成天就可以了,比較的簡單,如下:
PHP應用
$days=round(($enddate-$startdate)/3600/24) ;
echo $days; //days為得到的天數;
PHP應用2.分頁
PHP應用
/**
* author jackluo
* $url 地址,$count 總數,$page 當前面,$Pagesize 分頁大小
*/
function page_paper($url,$count,$page,$pagesize){
$allpage = ceil($count/$pagesize);
if($allpage<=3){
for($i=1;$i<=$allpage;$i++){
if($i==$page){
echo '<a href="'.$url.'&page='.$page.'" class="page_ovr">'.$i.'</a>';
}else{
echo '<a href="'.$url.'&page='.$i.'" >'.$i.'</a>';
}
}
}else{
$currentpage = $allpage-$page;
if($page<=3){
for($i=1;$i<=$page;$i++){
if($i == $page){
echo '<a href="'.$url.'&page='.$i.'" class="page_ovr">'.$i.'</a>';
}else{
echo '<a href="'.$url.'&page='.$i.'" >'.$i.'</a>';
}
}
//后三條
if($currentpage<=3){
for($i=($page+1);$i<=$allpage;$i++){
echo '<a href="'.$url.'&page='.$i.'" >'.$i.'</a>';
}
}else{
for($i=($page+1);$i<=($page+3);$i++){
echo '<a href="'.$url.'&page='.$i.'" >'.$i.'</a>';
}
}
}else{
//前三條
for($i=($page-3);$i<=$page;$i++){
if($i == $page){
echo '<a href="'.$url.'&page='.$i.'" class="page_ovr">'.$i.'</a>';
}else{
echo '<a href="'.$url.'&page='.$i.'" >'.$i.'</a>';
}
}
if($currentpage<=3){
for($i=($page+1);$i<=$allpage;$i++){
echo '<a href="'.$url.'&page='.$i.'" >'.$i.'</a>';
}
}else{
//后三條
for($i=($page+1);$i<=($page+3);$i++){
echo '<a href="'.$url.'&page='.$i.'" >'.$i.'</a>';
}
}
}
}
}
PHP應用3.獲取手機歸屬地(有時間,可以寫一個移動平臺的)
PHP應用
//獲得手機歸屬地
function phonenumberinfo($phone){
$list = array();
$soap = new SoapClient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl');
$result =(array) $soap->getMobileCodeInfo(array(
'mobileCode'=>$phone
));
list($moblie,$location,$lbs) = explode(' ', $result['getMobileCodeInfoResult']);
if($lbs){
$type = array('移動','電信','聯通');
foreach($type as $key=>$value){
$ps = strpos($lbs, $value);
if($ps){
$procver = substr($lbs, 0,$ps);
$list['province'] = $procver;
$list['operator'] = $value;
$list['city'] = $location;
$list['type'] = $key;
break;
}
}
return $list;
}
}
PHP應用希望本文所述對大家PHP程序設計有所贊助.
《PHP應用:PHP常用的小程序代碼段》是否對您有啟發,歡迎查看更多與《PHP應用:PHP常用的小程序代碼段》相關教程,學精學透。維易PHP學院為您提供精彩教程。