PHP small program code segments, PHP common program code segments _ PHP Tutorial

Source: Internet
Author: User
Common small program code segments in PHP and common program code segments in PHP. Common small program code segments in PHP, common program code segments in PHP this article describes common small program code segments in PHP. I would like to share with you for your reference. The details are as follows: 1. calculate the common small program code segments of PHP at two times, and the common PHP program code segments.

This example describes common small program code segments in PHP. 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.

Examples in this article describes common small program code segments in PHP. I would like to share it with you for your reference. The details are as follows: 1. calculate the two time periods...

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.