php 新闻文章分页代码实例教程
Jun 08, 2016 pm 05:27 PMunction 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) {
66 }
67 elseif ($page == $page_count) {
69 } else {
71 }
72 }

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari?
