-
- /**
- *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]'
-
-
-
-
-
-
-
|