LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 694|回复: 4

请教一个PHP的文件读取函数

[复制链接]
发表于 2003-7-31 15:59:05 | 显示全部楼层 |阅读模式
请问在PHP下用什么函数每次只读文件里面一行啊?(就是遇到换行符就停止)

我用过fread(),但它不行。
发表于 2003-7-31 16:15:33 | 显示全部楼层
fgets()呢??你试试看!找找php的manual阿!有帮助的!
发表于 2003-7-31 18:19:09 | 显示全部楼层
fgets也是一样的独到换行符的时候就会结束,可以这样来实现:
char str[100];
FILE *fd;
fd = fopen("a.txt","r");
while(fgets(str,100,fd)!=NULL)
    printf("%s",str);
 楼主| 发表于 2003-7-31 21:39:38 | 显示全部楼层

谢谢两位朋友的指点了.我去试试,

呵呵,实践才是硬道理
 楼主| 发表于 2003-7-31 22:45:52 | 显示全部楼层

好了,我自己把完整的代码写出来了。

<html>
<title>
Gateway status
</title>
<body>
<?php
$status_all=`arp -i eth0|grep -v Add|grep -v Mail|awk '{print $1}'|wc|awk '{print $1}'`;
$status_all=$status_all-2;
echo "all online clients: $status_all"."<p>";

$status_allip=`arp -i eth0|grep -v Add|grep -v Mail|awk '{print $1}' > /www/allip.inf`;

echo "<br><table>";
//Open file
$fz=fopen("./allip.inf","r");

while (!feof($fz))
       {
    $buffer=fgets($fz,100);

    echo "<tr><td>$buffer</td></tr>";
        }

fclose ($fz);

echo "</table>";

?>
</body>
</html>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表