标签:com fwrite handle txt images fputs filename pen fopen
1.fread — 读取文件(可安全用于二进制文件)
语法:string fread ( int $handle , int $length )
$filename = "aa.txt"; $fp = fopen($filename, "a"); $con = "\r\n你好"; //循环写入 for ($i=0; $i <5; $i++) { //写入 fwrite($fp, $con); } fclose($fp);
结果:
2.file_put_contents — 将一个字符串写入文件
$con = "\r\n北京"; //file_put_contents和依次调用fopen(),fwrite(),fclose()功能一样,FILE_APPEND->内容追加,相当于a+ file_put_contents($filename,$con,FILE_APPEND);
结果:
3.fputs():向文件中写一行
$filename = "aa.txt"; $fp = fopen($filename, ‘r‘); for ($i=1; $i < 10;$i++) { fputs($fp,‘北京\r\n‘); }
标签:com fwrite handle txt images fputs filename pen fopen
原文地址:http://www.cnblogs.com/zxf100/p/6747400.html