This article mainly introduces the small program code segments commonly used by PHP, including the function code for calculating the time difference, paging, and querying the mobile phone home location, which has some reference value, for more information, see the example below. We will share this with you for your reference. The details are as follows:
1. calculate the time difference between the two days
$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");
The above php time and date function strtotime has converted the string date into a timestamp, so that we only need to subtract the two values and then convert the second to the day. the comparison is simple, as shown below:
$ Days = round ($ enddate-$ startdate)/3600/24); echo $ days; // days indicates the number of days;
2. paging
/*** Author jackluo * $ url address, $ count total, $ page current surface, $ Pagesize page 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 ''. $ 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. '';} // the last 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 {// The 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 {// The last three for ($ I = ($ page + 1); $ I <= ($ page + 3); $ I ++) {echo ''. $ I. '';}}}}}
3. get the mobile phone home location (if you have time, you can write a mobile platform)
// Obtain the function phonenumberinfo ($ phone) {$ list = array (); $ soap = new SoapClient ('http: // webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx? Wsdl '); $ result = (array) $ soap-> getMobileCodeInfo (array ('lelecode' => $ phone); list ($ moblie, $ location, $ lbs) = explode ('', $ result ['getlelecodeinforesult ']); 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 PHP programming.