PHP Common applet code snippet, PHP common program code Snippet _php Tutorial

Source: Internet
Author: User
Tags time and date

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.