PHP code to implement paging display of long articles
Release: 2016-07-25 09:03:40
Original
812 people have browsed it
-
- /**
- *Author: Wuniao heart
- *Code to realize paging of long articles
- *Principle:
- *Use an array to record the starting number of bytes of each page of the article (manually marked with p0, p1, p2...) , and then use the php function to operate this array to display the paginated article. For paging display, pass the ptag (same as the value of tag) value.
- *PHP functions used:
- *1, strlen("string") - Returns the length of the given string. - Returns the total number of bytes in the string.
- *2, strpos("string","matching character") - Returns the numeric position of the first occurrence of needle in the haystack string. - Returns the byte of the first matching character that appears in the string Ordinal.
- *3, substr("string","start position","end position") - substr() returns the portion of string specified by the start and length parameters. - Returns a number of characters at the specified start and end positions in the string .
- */
- $sql = "select * from article where id = 41 ";//Define the sql statement and return the content with ID 41
- $result = mysql_query($sql);//Execute the sql statement and return the result set
- $row = mysql_fetch_array($result);//From the array in the form of an array The record set returns
- $content = $row['content'];//Assign the article to the variable $content
- $articleCounts = strlen($content);//Return the total number of bytes of $content (article)
- $isTrue = true;//Loop tag
- $tag = 0;//Paging tag, array subscript
- echo "Total number of bytes: ".$articleCounts."
";//Test information
- //Looking for tags" ptag", and assign its position (number of bytes) to the array array[]
- while($isTrue){
- $startAt = strpos($content,"p".$tag);//Get the corresponding ptag Byte number
- if($startAt != false){ //If there is a tag (the return value is not false), then record the position
- $array[$tag++] = $startAt;
- }else{ //If there is no tag, then Assign value to array array[0]'
-
-
-
-
-
-
-
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31