> 백엔드 개발 > PHP 튜토리얼 > php对文本文件开展分页功能简单实现

php对文本文件开展分页功能简单实现

WBOY
풀어 주다: 2016-06-13 12:24:24
원래의
856명이 탐색했습니다.

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

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

    <meta http-equiv="Content-type" content="text/html">    <title>Paging</title>    <style><span style="color: #000000;">        a{            padding:<span style="color: #000000;">20px;        }    </style><span style="color: #000000;">php</span><span style="color: #008000;">//</span><span style="color: #008000;"> 中文字符处理</span><span style="color: #0000ff;">function</span> m_substr(<span style="color: #800080;">$str</span>, <span style="color: #800080;">$start</span>, <span style="color: #800080;">$length</span><span style="color: #000000;">){    </span><span style="color: #800080;">$str_length</span> = <span style="color: #800080;">$start</span> + <span style="color: #800080;">$length</span>; <span style="color: #008000;">//</span><span style="color: #008000;"> 获取截取总长度</span>    <span style="color: #800080;">$tmp_str</span> = ""<span style="color: #000000;">;    </span><span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$str_length;<span style="color: #800080;">$i</span>++<span style="color: #000000;">){        </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">ord</span>(<span style="color: #008080;">substr</span>(<span style="color: #800080;">$str</span>, <span style="color: #800080;">$i</span>, 1)) == 0x0a<span style="color: #000000;">){            </span><span style="color: #800080;">$tmp_str</span> .= "<br>"<span style="color: #000000;">;        }        </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">ord</span>(<span style="color: #008080;">substr</span>(<span style="color: #800080;">$str</span>, <span style="color: #800080;">$i</span>, 1))>0xa0<span style="color: #000000;">){            </span><span style="color: #800080;">$tmp_str</span> .= <span style="color: #008080;">substr</span>(<span style="color: #800080;">$str</span>, <span style="color: #800080;">$i</span>, 2<span style="color: #000000;">);            </span><span style="color: #800080;">$i</span>++<span style="color: #000000;">;        }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{            </span><span style="color: #800080;">$tmp_str</span> .= <span style="color: #008080;">substr</span>(<span style="color: #800080;">$str</span>, <span style="color: #800080;">$i</span>, 1<span style="color: #000000;">);        }    }    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$tmp_str</span><span style="color: #000000;">;}</span><span style="color: #008000;">//</span><span style="color: #008000;"> 传参处理</span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$_GET</span>['page'<span style="color: #000000;">])){    </span><span style="color: #800080;">$page</span> = <span style="color: #800080;">$_GET</span>['page'<span style="color: #000000;">];}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{    </span><span style="color: #800080;">$page</span> = 1<span style="color: #000000;">;}</span><span style="color: #800080;">$counter</span> = <span style="color: #008080;">file_get_contents</span>("example.txt"<span style="color: #000000;">);</span><span style="color: #800080;">$length</span> = <span style="color: #008080;">strlen</span>(<span style="color: #800080;">$counter</span><span style="color: #000000;">);</span><span style="color: #800080;">$page_count</span> = <span style="color: #008080;">ceil</span>(<span style="color: #800080;">$length</span>/400<span style="color: #000000;">);</span><span style="color: #800080;">$pre_str</span> = m_substr(<span style="color: #800080;">$counter</span>, 0, (<span style="color: #800080;">$page</span>-1)*400<span style="color: #000000;">);</span><span style="color: #800080;">$now_str</span> = m_substr(<span style="color: #800080;">$counter</span>, 0, <span style="color: #800080;">$page</span>*400<span style="color: #000000;">);</span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">substr</span>(<span style="color: #800080;">$now_str</span>, <span style="color: #008080;">strlen</span>(<span style="color: #800080;">$pre_str</span>), <span style="color: #008080;">strlen</span>(<span style="color: #800080;">$now_str</span>)-<span style="color: #008080;">strlen</span>(<span style="color: #800080;">$pre_str</span><span style="color: #000000;">));</span><span style="color: #0000ff;">echo</span> "<br><br>"<span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> "当前页".<span style="color: #800080;">$page</span>."/".<span style="color: #800080;">$page_count</span><span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> "<a href="index.php?page=1">Index</a>"<span style="color: #000000;">;</span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$page</span>>1<span style="color: #000000;">){    </span><span style="color: #0000ff;">echo</span> "<a href="index.php?page=%22.(<span%20style=%22color:%20#800080;%22>%24page</span>-1).%22">Pre</a>"<span style="color: #000000;">;}</span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$page</span>$page_count<span style="color: #000000;">){    </span><span style="color: #0000ff;">echo</span> "<a href="index.php?page=%22.(<span" style="color: #800080;">$page+1).">Next</a>"<span style="color: #000000;">;}</span><span style="color: #0000ff;">echo</span> "<a href="index.php?page=<span" style="color: #800080;">$page_count>End</a>"<span style="color: #000000;">;</span>?>
로그인 후 복사

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿