file
file
Reads entire file into an array
**file** string $filename int $flags $context
Reads an entire file into an array.
Opmerking: > You can use to return the contents of a file as a string.
file_get_contents
filenamePath to the file.
flags
The optional parameter can be one, or
more, of the following constants:
`flags``FILE_USE_INCLUDE_PATH`
Search for the file in the .
include_path
FILE_IGNORE_NEW_LINESOmit newline at the end of each array element.
FILE_SKIP_EMPTY_LINESSkip empty lines.
FILE_NO_DEFAULT_CONTEXTDon't use the default context.
context
Returns the file in an array. Each element of the array corresponds to a
line in the file, with the newline still attached. Upon failure,
returns false.
file
Opmerking: > Each line in the resulting array will include the line ending, unless is used.
FILE_IGNORE_NEW_LINES
As of PHP 8.3.0, throws a
if includes any invalid values, such
as .
flags``FILE_APPEND
Emits an level error if the file
does not exist.
E_WARNING
Voorbeeld: example
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.example.com/');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
// Using the optional flags parameter
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
file_get_contents``readfile``fopen``fsockopen``popen``include``stream_context_create