开发者

How do I read a text file line by line?

开发者 https://www.devze.com 2023-01-04 20:10 出处:网络
suppose I do have a text file with these lines name: Mathew Age : 32 Country : USA Location : California bla bla bla....

suppose I do have a text file with these lines

name: Mathew Age : 32 Country : USA Location : California bla bla bla....

What I want is I want a php code which can read this file an开发者_运维问答d display result to a webpage.


Use this code (untested):

$fp = fopen('filename.php');
while (!eof($fp)) {
    $line = fgets($fp);
    // Add code to display the values how you want
    echo $line."<br>";
}
fclose($fp);

That will loop through the file line by line. Each line will be assigned to the $line variable, and then you can manipulate and display the values how you would like.


file() function reads a file into an array where one element represents a string in the file


Display the actual text or remove the name:, etc?

Use the file() function (tutorial?) to read the file in and then echo out / process each line.

0

精彩评论

暂无评论...
验证码 换一张
取 消