Analysis of paging source code for PHP writing content

Source: Internet
Author: User
The so-called content paging refers to paging long content according to the tag you set. This article involves two areas, one is obtaining the address, there are a lot of paging tutorials on the Internet, but the addresses are fixed. if there is a comment page and the article ID called, it will be very troublesome, PHP100 video tutorial "> <LINKhref =" http://www.php100.com/

The so-called content paging refers to paging long content according to the tag you set. This article involves two areas, one is obtaining the address, there are a lot of paging tutorials on the Internet, but the addresses are fixed. if there is a comment page and the article ID called, it will be very troublesome, in this paper, the PHP100 video tutorial paging principle (http://www.php100.com/html/shipinjiaocheng/PHP100shipinjiaocheng/2009/0416/807.html) ideas, there are unclear shoes can see this tutorial, while using some content processing functions and array knowledge, I wrote such an article for the first time. sorry if the statement is unclear.

Let's take a look at it first:

 

 

For more paging effects, there are many such styles in the php100 Forum. here we will share the CSS style code in the image:

CSS:

 
 
  1. DIV.digg {PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center}  
  2. DIV.digg A {BORDER-RIGHT: #aaaadd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #aaaadd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #aaaadd 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #aaaadd 1px solid; TEXT-DECORATION: none}  
  3. DIV.digg A:hover {BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid}  
  4. DIV.digg A:active {BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid}  
  5. DIV.digg SPAN.current {BORDER-RIGHT: #000099 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #000099 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #000099 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #000099 1px solid; BACKGROUND-COLOR: #000099}  
  6. DIV.digg SPAN.disabled {BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid} 

PHP code:

 
 
  1. $ Contents = "fjka; fjsa; # page # Generate [newpage] # page # component writing # page # parts and add # page # Paging code "; // original content with paging labels
  2. $ Cons = "fjka; fjsa; adsfasdfas code"; // The original content without the paging tag
  3.  
  4. Function conpage ($ contents ){
  5. $ Pagesss = '# page #'; // sets the page tag.
  6. $ A = strpos ($ contents, $ pagesss );
  7. If ($ ){
  8. $ Con = explode ($ pagesss, $ contents );
  9. $ Cons = count ($ con );
  10. @ $ P = ceil ($ _ GET ['P']);
  11. If (! $ P | $ p <0) $ p = 1;
  12. $ Url = $ _ SERVER ["REQUEST_URI"];
  13. $ Parse_url = parse_url ($ url );
  14. $ Url_query = $ parse_url ["query"];
  15. If ($ url_query ){
  16. $ Url_query = ereg_replace ("(^ | &) p = $ p", "", $ url_query );
  17. $ Url = str_replace ($ parse_url ["query"], $ url_query, $ url );
  18. If ($ url_query) $ url. = "& p"; else $ url. = "p ";
  19. } Else {
  20. $ Url. = "? P ";
  21. }
  22. If ($ cons <= 1) return false; // only one page is displayed without pagination
  23. $ Pagenav = "";
  24. For ($ I = 1; $ I <= $ cons; $ I ++ ){
  25. If ($ I = $ p ){
  26. $ Pagenav. = ''. $ p .'';
  27. } Else {
  28. $ Pagenav. = "$ I ";
  29. }
  30. }
  31. $ Pagenav. = "";
  32. Return $ con [$ P-1]. $ pagenav;
  33. } Else {
  34. Return $ contents;
  35. }
  36. }
  37.  
  38. Echo conpage ($ contents ); //
  39. Echo conpage ($ cons); //
  40.  
  41. ?>

This article is PHP100 Chinese community original works, please reprinted with the source: http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/1201/6940.html

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.