首頁 >後端開發 >php教程 >使用 PHP 讀取文字(TXT)檔 並分頁顯示_PHP教學

使用 PHP 讀取文字(TXT)檔 並分頁顯示_PHP教學

WBOY
WBOY原創
2016-07-22 09:03:031017瀏覽
<p></p> <p>[PHP]代碼</p> view source   print? <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">true</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>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn