PHP file Function _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.