php新聞內容分頁代碼實例教程

來源:互聯網
上載者:User
關鍵字 網路程式設計 PHP教程

新聞內容分頁代碼實例教程
unction explode_content($content, $length) {

02 $i = 0;

03 $k = 1;

04 $j = 0;

05 $wn = 0;

06 $s = '';

07 $e = 1;

08 $yh = 0;

09 while ($k) {

10 $d = $content[$i];

11 if ($d !== '') {

12 if (ord($d) > 127) {

13 $j++;

14 $num = 2;

15 $i++;

16 } else {

17 $num = 1;

18 }

19 $j++;

20 } else {

21 if ($s) {

22 $listdb[] = addslashes($s);

23 }

24 $k = 0;

25 }

26 $v1 = $j - $num;

27 $w = substr($content, $v1, $num);

28 if ($w !== '') {

29

30 if ($w == '<') {

31 $e = 0;

32 }

33 if (!$e && $w == '"') {

34 $yh++;

35 }

36 if ($e && $w != ' ' && $w != ' ') {

37 $wn++;

38 }

39 if ($w == '>' && $yh % 2 == 0) {

40 $e = 1;

41 }

42 $s .= $w;

43 }

44 if ($wn >= $length && $e) {

45 $listdb[] = addslashes($s);

46 $s = '';

47 $wn = 0;

48 }

49 $i++;

50 }

51 return $listdb;

52 }

53

54

55

56 分頁使用

57 $page_per = 500; 每頁字數
php文章內容分頁
58 $article_list = explode_content($article, $page_per); 拆分文章

59 $page_count = count($article_list);

60 $page = !empty($_GET['page']) ? intval($_GET['page']) : 1;

61 $page = ($page > $page_count && $page_count>0) ? $page_count : $page;

62 $article = strips教程lashes($article_list[$page -1]);

63 if ($page_count>1) {

64 if ($page == 1) {

65 $page_code = "<a href="news.php?id=$id&page=". ($page+1)."" >下頁</a> <a href="news.php?id=$id&page=$page_count">末頁</a> ";

66 }

67 elseif ($page == $page_count) {

68 $page_code = "<a href="news.php?id=$id&page=". ($page-1)."" >上頁</a> <a href="news.php?id=$id&page=1">首頁</a> ";

69 } else {

70 $page_code = "<a href="news.php?id=$id&page=". ($page+1)."" >下頁</a> <a href="news.php?id=$id&page=". ($page-1)."" >上頁</a> ";

71 }

72 }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.