Can I read a .TXT file with PHP?

前端 未结 6 952
遥遥无期
遥遥无期 2020-12-01 21:46

As I start the process of writing my site in PHP and MySQL, one of the first PHP scripts I\'ve written is a script to initialize my database. Drop/create the database. Dro

6条回答
  •  旧时难觅i
    2020-12-01 22:21

    You want to read line by line? Use fgets.

    $handle = @fopen("myfile.txt", "r");
    if ($handle) {
        while (($content = fgets($handle, 4096)) !== false) {
            //echo $content;
        }
        if (!feof($handle)) {
            echo "Error: unexpected fgets() fail\n";
        }
        fclose($handle);
    }
    

提交回复
热议问题