Solution for PHP to read data from the specified row of TXT
Source: Internet
Author: User
PHP reads the data of the specified row of TXT. now there is a large TXT, which exceeds the memory size (assuming that it is). to replace part of the text, if it is directly read, it will not work and the memory is not enough. I thought of a way to read the data cyclically, read 1000 rows first, perform the operation, clear the variables, and read the next 1000 rows cyclically. the file_get_contents () function seems to read all the content at once, I wonder if PHP has read data from the specified row of TXT.
Now there is a large TXT file that exceeds the memory size (suppose ),
To replace some text,
If the data is read directly, the memory is insufficient.
I tried to read it cyclically,
Read 1000 rows first, perform the operation, clear the variables, and read the next 1000 rows cyclically,
The file_get_contents () function seems to read all the content at once,
I don't know if there are other functions or methods.
------ Solution --------------------
Fgets: one row at a time
Fread one piece at a time (specified size)
If you need to directly modify the source file, use the r + method to open it.
Fseek is used to locate the file pointer during write-back, and ftell is used to retrieve the offset.
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.