In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how php modifies the data of a certain line of the file, which is very detailed and has a certain reference value. Friends who are interested must read it!
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The method of modifying a line of data in a file by php
Open the specified file by reading and writing
Use the while () loop + fgets () function to control the number of rows
The fgets () function can read files line by line, one line at a time
When you specify the number of rows, use the fseek () and fwrite () functions to modify the data for that row.
Implementation code:
The original contents of the test.txt file:
Modified content:
Description:
The feof () function checks whether the end of the file (EOF) has been reached. TRUE is returned if there is an error or the file pointer reaches the end of the file (EOF), otherwise FALSE is returned.
The fseek () function locates in the open file. This function moves the file pointer forward or backward from the current position to a new location, which is measured in bytes from the header of the file. The function returns 0 on success and-1 on failure. Note that moving to the location after the end of the file (EOF) does not cause an error.
The fwrite () function can write a string to a file.
The above is all the contents of the article "how to modify the data of a certain line in a file by php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.