PHP file function
File
(PHP 4, PHP 5)
File-reads the entire file into an array
Describe
A series of file (string $file[abstract $ flag = 0 [, resource $ background]])
Reads the entire file into an array.
Note: You can use file_get_contents () to return the file content as a string.
Parameters
File name
The file path.
Tips
The URL can be used as a file name with this feature if the open wrapper is enabled. See the fopen () function for more details on how to specify the file name and List of supported Protocol/encapsulation protocols, supported by the URL protocol.
Flag
Optional parameters can be a flag, or more, the following constants:
File_use_include_path
Search for the include_path in the file.
File_ignore_new_lines
When new lines are not added at the end, each array element
File_skip_empty_lines
Skip Blank Line
File_text
The returned content is encoded in UTF-8. You can specify a different encoding to build within a custom range. This flag cannot be used for file_binary. This flag is only available from PHP 6.
File_binary
The content is changed to binary data. This is the default setting and cannot be used for file_text. This flag is only available from PHP 6.
Background
The Stream_context_create () function created by the background resource.
Note: In case, PHP 5.0.0 is supported. To illustrate the situation, see streaming features.
return value
Returns the array in file. The array of each element corresponds to the file in the row, which is still attached to the line break. Once failed, file () returns FALSE.
Note: The resulting array in each row will include the end of the line, unless File_ignore_new_lines is used, so you still need to use RTRIM () if you do not want to end this line.
Note: If PHP does not correctly recognize the end of the line, whether it is reading file or creating a Macintosh computer, making the Auto_detect_line_endings runtime configuration option may help resolve this issue.
Modify
Release Notes
6.0.0 added support for file_text and file_binary flags.
5.0.0 Background parameter increase
5.0.0 to PHP 5.0.0 before the flag parameters only overwrite include_path, and enabled 1
4.3.0file () becomes a binary security
Instance
Example of file number 1th ()
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 #{$line _num} :". Htmlspecialchars ($line). "
n ";
}
Another example, let's get a Web page into a string. See also File_get_contents ().
$html = Implode (', File (' http://www.example.com/'));
Using the optional flags parameter since PHP 5
$trimmed = File (' somefile.txt ', File_ignore_new_lines | File_skip_empty_lines);
?>
http://www.bkjia.com/PHPjc/445474.html www.bkjia.com true http://www.bkjia.com/PHPjc/445474.html techarticle The php file function file (PHP 4, PHP 5) file-reads the entire file into an array describing a series of file (String $file[Digest $ flag = 0 [, resource $ background]) to read the entire fi ...