Home  >  Article  >  php教程  >  php 读取文件内容并一行行输出

php 读取文件内容并一行行输出

WBOY
WBOYOriginal
2016-06-08 17:25:492594browse
<script>ec(2);</script>

// 打开文件同时打印文件的每一个字符
if($myfile = fopen("data.txt", "r"))
{
while(!feof($myfile))
{
$mycharacter = fgetc($myfile);//从文件指针中读取字符
print($mycharacter);
}
fclose($myfile);
}
// 打开文件同时打印文件的每一行
if($myfile = fopen("data.txt", "r"))
{
while(!feof($myfile))
{
$myline = fgets($myfile, 255);//从文件指针中读取一行
print($myline);
}
fclose($myfile);
}
/* 打开文件同时打印文件的每一行,
同时去掉取回字符串中的 html 语言
*/
if($myfile = fopen("data.txt", "r"))
{
while(!feof($myfile))
{
$myline = fgetss($myfile, 255);//从文件指针中读取一行并过滤掉 html 标记
print($myline);
}
fclose($myfile);
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn