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

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

WBOY
Release: 2016-06-08 17:25:49
Original
2644 people have browsed it
<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);
}
?>

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template