Php: how to open a file in read-only mode _ PHP Tutorial

Source: Internet
Author: User
Php implements the method of opening files in read-only mode. Php: how to open a file in read-only mode this article mainly introduces php's method of opening a file in read-only mode. The example analyzes the function and usage skills of fopen function in php, how to open a file in read-only mode using php

This article describes how to open a file in read-only mode in php. The example analyzes the function and usage skills of the fopen function in php. For more information, see

This example describes how to open a file in read-only mode in php. Share it with you for your reference. The specific analysis is as follows:

In php, you can open a file through fopen (). The second parameter is set to "r", indicating that the file is opened in read-only mode. the function returns a file handle, other functions can use this file handle to read files in different ways.

?

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 results:

Type of file handle: resource
The first line from the file handle: Welcome to sharejs.com php tutorials

After the file is read, use the fclose () function to close the file handle to release the resource.

I hope this article will help you with php programming.

This article describes how to open a file in read-only mode in php. The example analyzes the function and usage skills of fopen function in php...

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.