PHP example of the function of Google page effect

Source: Internet
Author: User
Tags php example wordpress php
This article mainly introduces PHP to realize the page-like effect of Google paging function, an example of PHP implementation of paging related techniques. We hope to help you. The example in this article describes the page function that PHP implements to imitate the Google paging effect. Share to everyone for your reference.

Specific as follows:

/** * Paging function * @param int $total Total pages * @param int $pagesize a few * @param string $pkey URL in page variable name * @param string $url base U  RL, where {page} is replaced with page number * Dependency function Request_uri httpint */function page ($total, $pagesize =10, $pkey = ' P ', $url =null) {$a _num=10;  $first = ' home ';  $last = ' last ';  $pre = ' Upper page ';  $next = ' next page ';  $a _num= $a _num%2==0 $a _num+1: $a _num; if (! $url) {$url =preg_replace ("/&?{    $pkey}=[^&]{0,}/",", Request_uri ()); $url =strpos ($url, '? ') ===false? $url. '? '. $pkey. ' ={page} ': $url. ' & '. $pkey. '  ={page} ';  } $pages =ceil ($total/$pagesize);  $curpage =httpint ($pkey, false,1); $curpage = $curpage > $pages | |  $curpage <=0?1: $curpage;//The current page has a super range of 1 $body = "; $prefix ="; $subfix = "; $start = $curpage-($a _num-1)/2;//start Page $end = $curpage + ($a _num-1)/2;  End page $start = $start <=0?1: $start; Start page over range correction $end = $end > $pages? $pages: $end;//End page over-range correction if ($pages >= $a _num) {//Total pages greater than the number of page if ($curpage <= ($a _num-1 )/2) {$end = $a _num;} The current page is on the left half of the right if ($end-$curpage <= ($a _num-1)/2) {$start-=5-($end-$curpage);} CurrentPage in the right half of the left} for ($i = $start; $i <= $end; $i + +) {if ($i = = $curpage) {$body. = ' <b> ' $i. ' </b> '; }else{$body. = ' <a href= "'. Str_replace (' {page} ', $i, $url). '"     > '. $i. ' </a> '; }} $prefix = ($curpage ==1? ': ' <a href= "'. Str_replace (' {page} ', 1, $url). '" > '. $first. ' </a><a href= "'. Str_replace (' {page} ', $curpage-1, $url). '" > '. $pre. '  </a> '); $subfix = ($curpage = = $pages? ": ' <a href=" '. Str_replace (' {page} ', $curpage +1, $url). ' " > '. $next. ' </a><a href= "'. Str_replace (' {page} ', $pages, $url). '" > '. $last. '  </a> ');  $info = "page {$curpage}/{$pages}"; $go = ' <script>function ekup () {if (event.keycode==13) {Clkyup ()}} function Clkyup () {if (!/\d+/.test (document.getElementById (\ ' gsd09fhas9d\ ').) {alert (\ ' Please enter page number!\ '); return;}; Location=\ '. $url. ' \ '. replace (/\\{page\\}/,document.getelementbyid (\ ' gsd09fhas9d\ '). value);} </script><input onkeyup= "Ekup ()" type= "text" id= "gsd09fhas9d" style= "Width:40px;vertical-align: Text-baseline;padding:0 2px;font-size:10px;border:1px solid Gray; /> <span id= "Gsd09fhas9daa" onclick= "Clkyup ();" style= "cursor:pointer;text-decoration:underline;"  > Go to </span> '; Return $prefix. $body. $subfix. $info. $go;} /** * Description: Get a universal solution for _server[' Request_uri '] value */function Request_uri () {if (Isset ($_server[' Request_uri ')) {$uri = $_  server[' Request_uri '];    } else {if (Isset ($_server[' argv ')) {$uri = $_server[' php_self ']. '? '. $_server[' argv '][0];    } else {$uri = $_server[' php_self '). '? '. $_server[' query_string ']; }} return $uri;} /** * Gets the integer that is passed by HTTP * @param string $key parameter name * @param bool $ispost take post pass, default is True http://blog.ddian.cn * @return integer, illegal Shime think $default */function Httpint ($key, $ispost =true, $default =0) {if ($ispost) {if (Isset ($_post[$key])) {if (em       Pty ($_post[$key]) {return $default;         } else {$val = Trim ($_post[$key]);         if (Preg_match ("/^\-?\d+$/", $val)) return intval ($val); else return $Default     }} else {return $default;       }} else {if (Isset ($_get[$key])) {if (Empty ($_get[$key)) {return $default;         } else {$val = Trim ($_get[$key]);         if (Preg_match ("/^\-?\d+$/", $val)) {return intval ($val);         } else {return $default;     }}} else {return $default; }   }}

Related recommendations:

PHP Paging (limit)

PHP Paging principle Detailed

Wordpress PHP page Code _php Tutorial

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.