PHP implements a read-only way to open a file _php tutorial

Source: Internet
Author: User

PHP implementation method for opening files as read-only


This article mainly introduces the PHP implementation to open the file in a read-only way, the example analysis of PHP fopen function and the use of skills, the need for friends can refer to the following

The example in this article describes how PHP implements open files as read-only. Share to everyone for your reference. The specific analysis is as follows:

PHP can open a file through fopen (), the second parameter is set to "R" to indicate that it is read-only open, the function returns a file handle, and other functions can read the file in different ways through this file handle

?

1

2

3

4

5

6

$file = fopen ("/tmp/file.txt", "R");

Print ("Type of File Handle:".) GetType ($file). "\ n");

Print ("The first line from the file handle:".) Fgets ($file));

Fclose ($file);

?>

The above code returns the following result

Type of File Handle:resource
The first line from the file handle:welcome to sharejs.com PHP tutorials

After the file read is complete, you need to close the file handle using the Fclose () function to free up resources

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/968672.html www.bkjia.com true http://www.bkjia.com/PHPjc/968672.html techarticle PHP Implementation method of opening a file as read-only this article mainly introduces the PHP implementation to open the file in a read-only way, the example analysis of PHP fopen function and the use of skills, need ...

  • 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.