PHP commonly used small program code snippets, PHP common program code snippet
This article is an example of a common PHP applet code snippet. Share to everyone for your reference, as follows:
1. Calculate the difference between two time 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 the two values subtract, and then turn the second into the sky can be, the comparison is simple, as follows:
$days =round (($enddate-$startdate)/3600/24); Echo $days; Days for the day to get;
2. Paging
/*** author jackluo* $url address, total $count, $page current polygon, $Pagesize paging size */function Page_paper ($url, $count, $page, $pagesize) {$all page = Ceil ($count/$pagesize); if ($allpage <=3) {for ($i =1; $i <= $allpage; $i + +) {if ($i = = $page) {echo '. $i. }else{echo '. $i. '; }}}else{$currentpage = $allpage-$page; if ($page <=3) {for ($i =1; $i <= $page; $i + +) {if ($i = = $page) {echo '. $i. }else{echo '. $i. '; }}//After three if ($currentpage <=3) {for ($i = ($page + 1); $i <= $allpage; $i + +) {echo '. $i. '; }}else{for ($i = ($page + 1), $i <= ($page +3), $i + +) {echo '. $i. '; }}}else{//First three for ($i = ($page-3); $i <= $page; $i + +) {if ($i = = $page) {echo '. $i. }else{echo '. $i. '; }} if ($currentpage <=3) {for ($i = ($page + 1); $i <= $allpage; $i + +) {echo '. $i. '; }}else{//After three for ($i = ($page + 1); $i <= ($page +3); $i + +) {echo '. $i. '; } } } }}
3. Get the phone attribution (time, can write a mobile platform)
Get the 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 is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1071393.html www.bkjia.com true http://www.bkjia.com/PHPjc/1071393.html techarticle php commonly used small program code snippet, PHP common program code snippet This article describes the PHP commonly used small program code snippets. Share to everyone for your reference, as follows: 1. Calculate two time ...