Home > Backend Development > PHP Tutorial > How to open a file in read-only mode in php_PHP tutorial

How to open a file in read-only mode in php_PHP tutorial

WBOY
Release: 2016-07-13 10:03:18
Original
2036 people have browsed it

How to open files in read-only mode in php

This article mainly introduces the method of opening files in read-only mode in php, and analyzes the fopen function in php with examples. For functions and usage tips, friends in need can refer to it

The example in this article describes the method of opening files in read-only mode in PHP. Share it with everyone 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" to indicate that it has been opened in read-only mode. The function returns a file handle, and other functions can use this file handle to perform different operations on the file. Read

?

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);

?>

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 reading is completed, you need to use the fclose() function to close the file handle to release resources I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/968672.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968672.htmlTechArticleHow to open files in read-only mode in php. This article mainly introduces how to open files in read-only mode in php. The method and example analysis of the functions and usage skills of the fopen function in php require...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template