This article is an example of the code snippet commonly used in PHP. Share to everyone for your reference, specific as follows:
1. Calculate the difference of two times a few days
$startdate =strtotime ("2009-12-09");
$enddate =strtotime ("2009-12-05");
The PHP time and date function above Strtotime has turned the string date into a timestamp, so as long as you subtract two values and then turn the seconds into days, the comparison is simple, as follows:
$days =round (($enddate-$startdate)/3600/24);
Echo $days; Days for the day;
2. Paging
/** * Author Jackluo * $url address, total $count, $page current face, $Pagesize paging size/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> '; }//Three 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{//Top three 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{//After three for ($i = ($page + 1); $i <= ($page +3); $i + +) {echo ' <a href= '. $url. '
&page= '. $i. ' > '. $i. ' </a> ';
}
}
}
}
}
3. Get the place where the mobile phone belongs (have time, can write a mobile platform)
Get cell phone Attribution
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 (' Mobile ', ' telecom ', ' Unicom ');
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;
}
I hope this article will help you with the PHP program design.