view source print?<?php // you should save this file as m php session_start() if ( empty ( $page )) { $page = } if (isset( $_GET [ page ])==TRUE) { $page = $_GET [ page ]} ?> <> <head> <meta equiv= "Content Type" content= "text/charset=UTF " /> <title>qqview Read Result</title> <style type= "text/css" > <! STYLE {font size: px} STYLE {font size: px} > </style> </head> <body> <table width= " %" bgcolor= "#CCCCCC" > <tr> <td > <?php if ( $page ){ $counter = file_get_contents ( "example txt" ) // read the file into a string $length = strlen ( $counter ) $page_count = ceil ( $length / ) function msubstr( $str$start$len ){ $strlength = $start + $len $tmpstr = "" for ( $i = $i < $strlength $i ++) { if (ord( substr ( $str$i ))== x a) { $tmpstr = <br /> } if (ord( substr ( $str$i ))>xa ) { $tmpstr = substr ( $str$i ) $i ++ } else { $tmpstr = substr ( $str$i )} } return $tmpstr } // 截取中文字符串 $c =msubstr( $counter ( $page )* ) $c =msubstr( $counter$page * ) echo substr ( $c strlen ( $c ) strlen ( $c ) strlen ( $c )) }?> </td> </tr> </table> <table width= " %" bgcolor= "#cccccc" > <tr> <td width= " %" align= "center" valign= "middle" ><span class = "STYLE " ><?php echo $page ?>/ <?php echo $page_count ?>页 </span></td> <td width= " %" height= " " align= "left" valign= "middle" ><span class = "STYLE " ><?php echo "<a href=m php?page= >首页</a>" if ( $page != ){ echo "<a href=m php?page=" ( $page ) ">上一页</a>" } if ( $page < $page_count ){ echo "<a href=m php?page=" ( $page + ) ">下一页</a>" } echo "<a href=m php?page="$page_count">尾页</a>" ?> </span></td> </tr> </table> </body> </> lishixinzhi/Article/program/PHP/201311/21215
利用PHP读取文本
文件的
内容,其实很简单,我们只需要掌握函数“file_get_contents()”的使用就可以了。下面,小编将作详细的介绍。
工具/原料
电脑一台
WAMP开发环境
方法/步骤
file_get_content()函数介绍。使用file_get_contents()获取txt文件的内容,具体参数说明如下:
2
具体实例说明。从文本文件tst.txt中读取里面的内容并显示在浏览器中,具体代码和图示如下:
<?php
$file = 'tst.txt'
$content = file_get_contents($file)//读取文件中的内容
echo $content
?>
评论列表(0条)