网站地图    收藏   

主页 > php专栏 > php文件操作 >

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

来源:自学PHP网    时间:2014-11-28 00:07 作者: 阅读:次

[导读] ?php 打开文件同时打印文件的每一个字符if($myfile=fopen(data txt,r)){while(!feof($myfile)){$mycharacter=fgetc($myfile); 从文件指针中读取字符print($mycharacter);}fclose($myfile);...

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

  1. <?php 
  2. // 打开文件同时打印文件的每一个字符 
  3. if($myfile = fopen("data.txt", "r")) 
  4. { 
  5. while(!feof($myfile)) 
  6. { 
  7. $mycharacter = fgetc($myfile);//从文件指针中读取字符 
  8. print($mycharacter); 
  9. } 
  10. fclose($myfile);//开源代码phpfensi.com 
  11. }  
  12. // 打开文件同时打印文件的每一行 
  13. if($myfile = fopen("data.txt", "r")) 
  14. { 
  15. while(!feof($myfile)) 
  16. { 
  17. $myline = fgets($myfile, 255);//从文件指针中读取一行 
  18. print($myline); 
  19. } 
  20. fclose($myfile); 
  21. }  
  22. /* 打开文件同时打印文件的每一行, 
  23. 同时去掉取回字符串中的 html 语言 
  24. */ 
  25. if($myfile = fopen("data.txt", "r")) 
  26. { 
  27. while(!feof($myfile)) 
  28. { 
  29. $myline = fgetss($myfile, 255);//从文件指针中读取一行并过滤掉 html 标记 
  30. print($myline); 
  31. } 
  32. fclose($myfile); 
  33. }  
  34. ?> 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论