php对文本文件进行分页功能简单实现,_PHP教程

WBOY
Lepaskan: 2016-07-13 16:53:56
asal
939 orang telah melayarinya

php对文本文件进行分页功能简单实现,

php对文本文件进行分页功能简单实现

<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html";charset="gb2312">
    <title>Paging</title>
    <style><span>
        a{
            padding</span>:<span>20px;
        }
    </span></style>
</head>
<body>

<?<span>php
</span><span>//</span><span> 中文字符处理</span>
<span>function</span> m_substr(<span>$str</span>, <span>$start</span>, <span>$length</span><span>){
    </span><span>$str_length</span> = <span>$start</span> + <span>$length</span>; <span>//</span><span> 获取截取总长度</span>
    <span>$tmp_str</span> = ""<span>;
    </span><span>for</span>(<span>$i</span>=0;<span>$i</span><<span>$str_length</span>;<span>$i</span>++<span>){
        </span><span>if</span>(<span>ord</span>(<span>substr</span>(<span>$str</span>, <span>$i</span>, 1)) == 0x0a<span>){
            </span><span>$tmp_str</span> .= "<br>"<span>;
        }
        </span><span>if</span>(<span>ord</span>(<span>substr</span>(<span>$str</span>, <span>$i</span>, 1))>0xa0<span>){
            </span><span>$tmp_str</span> .= <span>substr</span>(<span>$str</span>, <span>$i</span>, 2<span>);
            </span><span>$i</span>++<span>;
        }</span><span>else</span><span>{
            </span><span>$tmp_str</span> .= <span>substr</span>(<span>$str</span>, <span>$i</span>, 1<span>);
        }
    }
    </span><span>return</span> <span>$tmp_str</span><span>;
}
</span><span>//</span><span> 传参处理</span>
<span>if</span>(<span>isset</span>(<span>$_GET</span>['page'<span>])){
    </span><span>$page</span> = <span>$_GET</span>['page'<span>];
}</span><span>else</span><span>{
    </span><span>$page</span> = 1<span>;
}

</span><span>$counter</span> = <span>file_get_contents</span>("example.txt"<span>);
</span><span>$length</span> = <span>strlen</span>(<span>$counter</span><span>);
</span><span>$page_count</span> = <span>ceil</span>(<span>$length</span>/400<span>);
</span><span>$pre_str</span> = m_substr(<span>$counter</span>, 0, (<span>$page</span>-1)*400<span>);
</span><span>$now_str</span> = m_substr(<span>$counter</span>, 0, <span>$page</span>*400<span>);
</span><span>echo</span> <span>substr</span>(<span>$now_str</span>, <span>strlen</span>(<span>$pre_str</span>), <span>strlen</span>(<span>$now_str</span>)-<span>strlen</span>(<span>$pre_str</span><span>));

</span><span>echo</span> "<br><br>"<span>;
</span><span>echo</span> "当前页".<span>$page</span>."/".<span>$page_count</span><span>;
</span><span>echo</span> "<a href='index.php?page=1'>Index</a>"<span>;
</span><span>if</span>(<span>$page</span>>1<span>){
    </span><span>echo</span> "<a href='index.php?page=".(<span>$page</span>-1)."'>Pre</a>"<span>;
}
</span><span>if</span>(<span>$page</span><<span>$page_count</span><span>){
    </span><span>echo</span> "<a href=index.php?page=".(<span>$page</span>+1).">Next</a>"<span>;
}

</span><span>echo</span> "<a href=index.php?page=<span>$page_count</span>>End</a>"<span>;

</span>?>

</body>
</html>
Salin selepas log masuk

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1053804.htmlTechArticlephp对文本文件进行分页功能简单实现, php对文本文件进行分页功能简单实现 !DOCTYPEhtmlhead meta http-equiv="Content-type" content="text/html";charset="gb...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!