Can I read a .TXT file with PHP?

前端 未结 6 949
遥遥无期
遥遥无期 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条回答
  •  情话喂你
    2020-12-01 22:15

    All I need is a brief PHP example of how to open a TXT file on the server, read it sequentially, display the data on the screen, and close the file, as in this pseudo-code:

    echo file_get_contents('/path/to/file.txt');
    

    Yes that brief, see file_get_contents, you normally don't need a loop:

    $file = new SPLFileObject('/path/to/file.txt');
    foreach($file as $line) {
        echo $line;
    }
    

提交回复
热议问题