PHP를 사용하여 텍스트(TXT) 파일을 읽고 페이지_PHP 튜토리얼에 표시합니다.

WBOY
풀어 주다: 2016-07-22 09:03:03
원래의
992명이 탐색했습니다.
<p></p> <p>[PHP] 코드</p> 소스 보기 ​ 인쇄? <table> <tbody> <tr> <td class="number"><code>01</code></td> <td class="content"><code class="php plain"><?php </code><code class="php comments">//----------------you should save this file as m.php---------------- </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>02</code></td> <td class="content"><code class="spaces"> </code><code class="php plain">session_start(); </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>03</code></td> <td class="content"><code class="spaces"> </code><code class="php keyword">if</code> <code class="php plain">(</code><code class="php functions">empty</code><code class="php plain">(</code><code class="php variable">$page</code><code class="php plain">)) {</code><code class="php variable">$page</code><code class="php plain">=1;} </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>04</code></td> <td class="content"><code class="spaces"> </code><code class="php keyword">if</code> <code class="php plain">(isset(</code><code class="php variable">$_GET</code><code class="php plain">[</code><code class="php string">'page'</code><code class="php plain">])==TRUE) {</code><code class="php variable">$page</code><code class="php plain">=</code><code class="php variable">$_GET</code><code class="php plain">[</code><code class="php string">'page'</code><code class="php plain">]; } </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>05</code></td> <td class="content"><code class="php plain">?>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>06</code></td> <td class="content"><code class="php plain"><html>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>07</code></td> <td class="content"><code class="php plain"><head>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>08</code></td> <td class="content"><code class="php plain"><meta http-equiv=</code><code class="php string">"Content-Type"</code> <code class="php plain">content=</code><code class="php string">"text/html; charset=UTF-8"</code> <code class="php plain">/>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>09</code></td> <td class="content"><code class="php plain"><title>www.qqview.com-Read Result</title>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>10</code></td> <td class="content"><code class="php plain"><style type=</code><code class="php string">"text/css"</code><code class="php plain">>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>11</code></td> <td class="content"><code class="php plain"><!-- </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>12</code></td> <td class="content"><code class="php plain">.STYLE1 {font-size: 12px} </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>13</code></td> <td class="content"><code class="php plain">.STYLE2 {font-size: 18px} </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>14</code></td> <td class="content"><code class="php plain">-->  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>15</code></td> <td class="content"><code class="php plain"></style>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>16</code></td> <td class="content"><code class="php plain"></head>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>17</code></td> <td class="content"><code class="php plain"><body>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>18</code></td> <td class="content"><code class="php plain"><table width=</code><code class="php string">"100%"</code> <code class="php plain">bgcolor=</code><code class="php string">"#CCCCCC"</code><code class="php plain">>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>19</code></td> <td class="content"><code class="php plain"><tr>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>20</code></td> <td class="content"><code class="php plain"><td >  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>21</code></td> <td class="content"> <code class="php plain"><?php </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>22</code></td> <td class="content"><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$page</code><code class="php plain">){ </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>23</code></td> <td class="content"><code class="php variable">$counter</code><code class="php plain">=</code><code class="php functions">file_get_contents</code><code class="php plain">(</code><code class="php string">"example.txt"</code><code class="php plain">); </code><code class="php comments">//-------read the file into a string.------- </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>24</code></td> <td class="content"><code class="php variable">$length</code><code class="php plain">=</code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$counter</code><code class="php plain">); </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>25</code></td> <td class="content"><code class="php variable">$page_count</code><code class="php plain">=</code><code class="php functions">ceil</code><code class="php plain">(</code><code class="php variable">$length</code><code class="php plain">/5000); </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>26</code></td> <td class="content"><code class="spaces"> </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>27</code></td> <td class="content"><code class="php keyword">function</code> <code class="php plain">msubstr(</code><code class="php variable">$str</code><code class="php plain">,</code><code class="php variable">$start</code><code class="php plain">,</code><code class="php variable">$len</code><code class="php plain">){ </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>28</code></td> <td class="content"><code class="spaces"> </code><code class="php variable">$strlength</code><code class="php plain">=</code><code class="php variable">$start</code><code class="php plain"> </code><code class="php variable">$len</code><code class="php plain">; </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>29</code></td> <td class="content"><code class="spaces"> </code><code class="php variable">$tmpstr</code><code class="php plain">=</code><code class="php string">""</code><code class="php plain">; </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>30</code></td> <td class="content"><code class="spaces"> </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code><code class="php plain">=0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php variable">$strlength</code><code class="php plain">;</code><code class="php variable">$i</code><code class="php plain"> ) { </code></td> </tr> </tbody> </table><table> <tbody> <tr> <td class="number"><code>31</code></td> <td class="content"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(ord(</code><code class="php functions">substr</code><code class="php plain">(</code><code class="php variable">$str</code><code class="php plain">,</code><code class="php variable">$i</code><code class="php plain">,1))==0x0a) { </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>32</code></td> <td class="content"><code class="spaces"> </code><code class="php variable">$tmpstr</code><code class="php plain">.=</code><code class="php string">'<br />'</code><code class="php plain">; </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>33</code></td> <td class="content"> <code class="spaces">    </code><code class="php plain">} </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>34</code></td> <td class="content"> <code class="spaces">    </code><code class="php keyword">if</code><code class="php plain">(ord(</code><code class="php functions">substr</code><code class="php plain">(</code><code class="php variable">$str</code><code class="php plain">,</code><code class="php variable">$i</code><code class="php plain">,1))>0xa0) {  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>35</code></td> <td class="content"> <code class="spaces">        </code><code class="php variable">$tmpstr</code><code class="php plain">.=</code><code class="php functions">substr</code><code class="php plain">(</code><code class="php variable">$str</code><code class="php plain">,</code><code class="php variable">$i</code><code class="php plain">,2);  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>36</code></td> <td class="content"> <code class="spaces">        </code><code class="php variable">$i</code><code class="php plain"> ;  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>37</code></td> <td class="content"> <code class="spaces">    </code><code class="php plain">} </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>38</code></td> <td class="content"> <code class="spaces">    </code><code class="php keyword">else</code><code class="php plain">{  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>39</code></td> <td class="content"> <code class="spaces">        </code><code class="php variable">$tmpstr</code><code class="php plain">.=</code><code class="php functions">substr</code><code class="php plain">(</code><code class="php variable">$str</code><code class="php plain">,</code><code class="php variable">$i</code><code class="php plain">,1); }  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>40</code></td> <td class="content"> <code class="spaces">    </code><code class="php plain">}  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>41</code></td> <td class="content"> <code class="spaces">    </code><code class="php keyword">return</code> <code class="php variable">$tmpstr</code><code class="php plain">;  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>42</code></td> <td class="content"><code class="php plain">}  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>43</code></td> <td class="content"><code class="php comments">//--------------------------截取中文字符串--------------------------  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>44</code></td> <td class="content"> <code class="php variable">$c</code><code class="php plain">=msubstr(</code><code class="php variable">$counter</code><code class="php plain">,0,(</code><code class="php variable">$page</code><code class="php plain">-1)*5000);  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>45</code></td> <td class="content"> <code class="php variable">$c1</code><code class="php plain">=msubstr(</code><code class="php variable">$counter</code><code class="php plain">,0,</code><code class="php variable">$page</code><code class="php plain">*5000);  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>46</code></td> <td class="content"> <code class="php functions">echo</code> <code class="php functions">substr</code><code class="php plain">(</code><code class="php variable">$c1</code><code class="php plain">,</code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$c</code><code class="php plain">),</code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$c1</code><code class="php plain">)-</code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$c</code><code class="php plain">));  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>47</code></td> <td class="content"><code class="php plain">}?>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>48</code></td> <td class="content"><code class="php plain"></td>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>49</code></td> <td class="content"><code class="php plain"></tr>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>50</code></td> <td class="content"><code class="php plain"></table>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>51</code></td> <td class="content"><code class="spaces"> </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>52</code></td> <td class="content"><code class="php plain"><table width=</code><code class="php string">"100%"</code> <code class="php plain">bgcolor=</code><code class="php string">"#cccccc"</code><code class="php plain">>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>53</code></td> <td class="content"><code class="php plain"><tr>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>54</code></td> <td class="content"><code class="php plain"><td width=</code><code class="php string">"42%"</code> <code class="php plain">align=</code><code class="php string">"center"</code> <code class="php plain">valign=</code><code class="php string">"middle"</code><code class="php plain">><span </code><code class="php keyword">class</code><code class="php plain">=</code><code class="php string">"STYLE1"</code><code class="php plain">> <?php </code><code class="php functions">echo</code> <code class="php variable">$page</code><code class="php plain">;?> / <?php </code><code class="php functions">echo</code> <code class="php variable">$page_count</code><code class="php plain">;?> 页 </span></td>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>55</code></td> <td class="content"><code class="php plain"><td width=</code><code class="php string">"58%"</code> <code class="php plain">height=</code><code class="php string">"28"</code> <code class="php plain">align=</code><code class="php string">"left"</code> <code class="php plain">valign=</code><code class="php string">"middle"</code><code class="php plain">> </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>56</code></td> <td class="content"><code class="php plain"><span </code><code class="php keyword">class</code><code class="php plain">=</code><code class="php string">"STYLE1"</code><code class="php plain">> </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>57</code></td> <td class="content"> <code class="php plain"><?php </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>58</code></td> <td class="content"><code class="php functions">echo</code> <code class="php string">"<a href=m.php?page=1>首页</a> "</code><code class="php plain">;   </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>59</code></td> <td class="content"> <code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$page</code><code class="php plain">!=1){  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>60</code></td> <td class="content"> <code class="spaces">    </code><code class="php functions">echo</code> <code class="php string">"<a href=m.php?page="</code><code class="php plain">.(</code><code class="php variable">$page</code><code class="php plain">-1).</code><code class="php string">">上一页</a> "</code><code class="php plain">;  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>61</code></td> <td class="content"><code class="php plain">}  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>62</code></td> <td class="content"> <code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$page</code><code class="php plain"><</code><code class="php variable">$page_count</code><code class="php plain">){ </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>63</code></td> <td class="content"><code class="spaces"> </code><code class="php functions">echo</code> <code class="php string">"<a href=m.php?page="</code><code class="php plain">.(</code><code class="php variable">$page</code><code class="php plain"> 1).</code><code class="php string">">下一页</a> "</code><code class="php plain">;  </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>64</code></td> <td class="content"><code class="php plain">} </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>65</code></td> <td class="content"> <code class="php functions">echo</code> <code class="php string">"<a href=m.php?page="</code><code class="php plain">.</code><code class="php variable">$page_count</code><code class="php plain">.</code><code class="php string">">尾页</a>"</code><code class="php plain">;   </code> </td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>66</code></td> <td class="content"><code class="php plain">?>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>67</code></td> <td class="content"><code class="php plain"></span> </td>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>68</code></td> <td class="content"><code class="php plain"></tr>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>69</code></td> <td class="content"><code class="php plain"></table>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>70</code></td> <td class="content"><code class="php plain"></body>  </code></td> </tr> </tbody> </table> <table> <tbody> <tr> <td class="number"><code>71</code></td> <td class="content"><code class="php plain"></html></code></td> </tr> </tbody> </table> <p align="left"></p> <div style="display:none;"> <span id="url" itemprop="url">http://www.bkjia.com/PHPjc/371822.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">참</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http: //www.bkjia.com/PHPjc/371822.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">[PHP]代码 원본 보기? 01 ?php //---이 파일을 m.php로 저장해야 합니다---------------- 02 session_start() ; 03 if ( 비어 있음 ( $page )) { $page =1;} 04 if (isset( $...</span> </div> <div class="art_confoot"></div>
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿