Php:file () and file_get_contents (): The log file is not read in the array form

Source: Internet
Author: User

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 &nbsp; 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

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.