File (), like file_get_contents (), reads the contents of a file. File_get_contents () outputs the entire file (cannot read the first line indent and line break in txt). The file () function reads entire files into an array. Like File_get_contents (), the difference is that file () returns files as an array . Each cell in the array is the corresponding line in the file, including the newline character. If it fails, it returns false.
Array
[0] Test1
[1]
[2] Test2
)
Using the file () feature, we can use a looping method to put HTML line breaks and space characters together with the text.
Welcome.txt File Contents:
Test1
Test2
$welcomefile =file (' welcome.txt '); Returns the contents of an array
foreach ($welcomefile as $v) {
echo $v. ' <br> ';
}
With the code above, you can use the. Output band in PHP file and <br> line breaks to achieve line break.
Php:file () and file_get_contents (): The log file is not read in the array form