How do I read a text file line by line?
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.
精彩评论