当前位置:Gxlcms > PHP教程 > PHP读写文件代码

PHP读写文件代码

时间:2021-07-01 10:21:17 帮助过:17人阅读

<?php
    $str1 = "write something into file. ";
    $str2 = "this is a text file. ";
    $filename = "C:/data/01.txt";
    
    // 写文件
    $file = fopen($filename, "w");
    $w1 = fwrite($file, $str1);
    $w1 = fwrite($file, "\r\n");
    $w1 = fwrite($file, $str2);
    fclose($file);
    
    // 读文件
    $file = fopen($filename, "r");
    while (!feof ($file)) {  
        echo fgets($file) ."<br>" ;
    }
    fclose($file);
?>

人气教程排行