PHP read and write file code

巴扎黑
Release: 2016-11-23 13:23:50
Original
1072 people have browsed it

<?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);
?>
Copy after login

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template