一 代码
class="php" name="code"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>使用readfile()函数、file()函数和file_get_contents()函数分别读取文件count.txt的内容</title> <style type="text/css"> <!-- .STYLE2 { font-size: 16px; font-weight: bold; font-family: "华文琥珀"; color: #FFFFFF; } .STYLE3 {font-size: 12px} .STYLE4 {color: #999999} .STYLE5 { font-size: 12px; font-weight: bold; color: #999999; } --> </style> </head> <body> <table width="592" height="260" border="0" cellpadding="0" cellspacing="0" background="images/bg.JPG"> <tr> <td width="134" align="right" valign="middle" scope="col"> </td> <td width="35" rowspan="2" align="right" valign="middle" scope="col"> </td> <td height="40" colspan="2" align="center" valign="middle" scope="col"> <p> <span class="STYLE5">使用readfile()、file()和file_get_contents()读取count.txt</span></p> </td> </tr> <tr> <td width="134" align="right" valign="middle" scope="col"><span class="STYLE2">readfile函数:</span></td> <td width="398" align="left" valign="middle" scope="col"><span class="STYLE3"> <!-- 使用readfile()函数读取count.txt文件的内容 --> <?php readfile('count.txt'); ?> </span></td> <td width="25" align="center" valign="middle" scope="col"> </td> </tr> <tr> <td align="right" valign="middle" class="STYLE2">file函数:</td> <td rowspan="3" align="right" valign="middle" class="STYLE2"> </td> <td align="left" valign="bottom" class="STYLE3 STYLE4"> <!-- 使用file()函数读取count.txt文件的内容 --> <?php $f_arr = file('count.txt'); foreach($f_arr as $cont){ echo $cont."<br>"; } ?></td> <td width="25" rowspan="3" align="center" valign="middle"> </td> </tr> <tr> <td align="center" valign="middle" class="STYLE2"><p>file_get</p> <p>_contents函数:</p></td> <td align="left" valign="middle" class="STYLE3"> <!-- 使用file_get_contents()函数读取count.txt文件的内容 --> <?php $f_chr = file_get_contents('count.txt'); echo $f_chr; ?> </td> </tr> <tr> <td align="right" valign="top" class="STYLE2"> </td> <td height="20" align="center" valign="middle"> </td> </tr> </table> </body> </html>
?
二 运行结果