无为清净楼资源网 Design By www.qnjia.com
PHP文件读取操作相对于文件写入操作涉及更多的PHP文件操作函数,在代码实例中会详细介绍这些函数。
读取文本文件中存储数据的方式主要涉及的三个步骤及部分文件操作函数如下:
1、打开文件(文件操作函数:fopen)
2、文件数据读取(文件操作函数:fgets、file、readfile、feof等)
3、关闭文件(文件操作函数:fclose)
下面仍然以PHP文件读写操作代码实例讲解文件读取方法的具体应用,在实例中,通过调用不同的PHP文件读取操作函数读取文本文件中的数据,你可以加深PHP文件读取操作函数的理解,以便在PHP网站开发中合理应用。文本文件中写入的数据来自于PHP文件读写操作之文件写入教程,fopen函数中关于文件读写模式也可参考此文。
PHP文件读取操作代码实例
<"fread"; switch ($readFun) { case "fgetss": @$fp = fopen("leapsoulcn.txt","r") or die("system error"); $allowable_tags = "<h1>"; while (!feof($fp)) { $output = fgetss($fp,100,$allowable_tags); echo $output; } fclose($fp); break; case "fgetcsv": @$fp = fopen("leapsoulcn.txt","r") or die("system error"); while (!feof($fp)) { $output = fgetcsv($fp,100,"\t"); print_r($output); } fclose($fp); break; case "readfile": echo readfile("leapsoulcn.txt"); break; case "fpassthru": @$fp = fopen("leapsoulcn.txt","r") or die("system error"); if(!fpassthru($fp)) exit(); fclose($fp); break; case "file": $output = file("leapsoulcn.txt"); print_r($output); break; case "fgetc": @$fp = fopen("leapsoulcn.txt","r") or die("system error"); while (!feof($fp)) { $str = fgetc($fp); echo ($str == "\n""<br/>":$str); } fclose($fp); break; case "fread": @$fp = fopen("leapsoulcn.txt","r") or die("system error"); echo fread($fp,300); fclose($fp); break; default: @$fp = fopen("leapsoulcn.txt","r") or die("system error"); while (!feof($fp)) { $output = fgets($fp,100); echo $output; } fclose($fp); break; } "htmlcode"><"leapsoulcn.txt","r") or die("system error"); echo fread($fp,filesize("leapsoulcn.txt")); fclose($fp); "htmlcode"><"leapsoulcn.txt")) { //进行PHP文件读写操作 } ?>以上为大家介绍了PHP读取文件内容的各种方法,通过合理应用PHP文件读写操作函数,可以实现简单的留言本、网站log记录等功能。
标签:
PHP,文件读取
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 国风大师纯音系列《古筝仙子 常静演奏 十指弹一》1CD[FLAC][919MB]
- DasKapital-OneMustHaveChaosInsidetoGiveBirthtoaDancingStar(2024)[24-44.1]WAV
- 王菲.1999-《只爱陌生人》日本东芝版[低速原抓WAV+CUE]
- 张小英1987-金奖金曲第一集[新加坡版][WAV+CUE]
- 鹿晗.2015-重启【海蝶】【FLAC分轨】
- 张芸京.2012-小女孩【金牌大风】【WAV+CUE】
- 余天.2002-雄狮魅力金曲2CD(南方金点系列)【南方】【WAV+CUE】
- 银霞.1982-《结·SAYYESMYBOY》台湾复刻版[WAV+CUE]
- 梁汉文1993-火热动感[引进版][WAV+CUE]
- 梁汉文2008-EDMONDHITS48[香港]3CD[WAV+CUE]
- 国风大师纯音系列《童丽-[渭城曲]》1CD[WAV分轨][593.5MB]
- 国风大师纯音系列《许菱子《烧筝2》古筝曲集》1CD[WAV分轨][1.3GB]
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】