PHP Common Small program code snippets _php Tips

Source: Internet
Author: User
Tags soap time and date

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.

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.