Use PHP to read data

Source: Internet
Author: User
Using PHP to read files php I/O operations is not a little simpler than java. the same reading file java processing is cumbersome, and php is basically just a few pieces of code. From these aspects, php is really more convenient. this time I am sharing the php file operation to read several files. Method 1. reading common files is mainly about reading text files.

PHP's IO operations are not a little simpler than java's. the same reading of file java is complicated. php basically just comes out with a few pieces of code. From these points, php is really more convenient. this time I am sharing the php file operation to read several files.

1. reading common files is mainly about reading text files.

To read txt text files, php provides us with two common methods. let's start with the following code:

 

This method is best for reading small files. reading large files may have a great impact on apache, because the file is directly read. So it may be better to use the following

 0) {$ str. = fread ($ fp, $ buf); $ tem + = $ buf;} echo $ str;} else {die ("file does not exist ");} fclose ($ fp);?>

2. read the resource file or configuration file

For resource files or configuration files, php also provides us with the appropriate method. I personally think php is a good way to read such files, so I can simply look at my resource files.

The following code is used to read the resource file.

 $ Value) {echo "$ key: $ value "."
";}} Else {die (" The file does not exist ") ;}?>

Below is the program running

Is it easier to operate files than java?


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.