file Reads entire file into an array &reftitle.description; arrayfalsefile stringfilename intflags0 resourcenullcontext&null; Reads an entire file into an array. You can use file_get_contents to return the contents of a file as a string. &reftitle.parameters; filename Path to the file. &tip.fopen-wrapper; flags The optional parameter flags can be one, or more, of the following constants: FILE_USE_INCLUDE_PATH Search for the file in the include_path. FILE_IGNORE_NEW_LINES Omit newline at the end of each array element. FILE_SKIP_EMPTY_LINES Skip empty lines. FILE_NO_DEFAULT_CONTEXT Don't use the default context. context ¬e.context-support; &reftitle.returnvalues; 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, file returns &false;. Each line in the resulting array will include the line ending, unless FILE_IGNORE_NEW_LINES is used. ¬e.line-endings; &reftitle.errors; As of PHP 8.3.0, throws a ValueError if flags includes any invalid values, such as FILE_APPEND. Emits an E_WARNING level error if the file does not exist. &reftitle.changelog; &Version; &Description; 8.3.0 ValueError is thrown for any invalid values of flags. &reftitle.examples; <function>file</function> example $line) { echo "Line #{$line_num} : " . htmlspecialchars($line) . "
\n"; } // Using the optional flags parameter $trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); ?> ]]>
&reftitle.notes; &warn.ssl-non-standard; &reftitle.seealso; file_get_contents readfile fopen fsockopen popen include stream_context_create