Home Backend Development PHP Tutorial PHP读取TXT指定行的数据解决方法

PHP读取TXT指定行的数据解决方法

Jun 13, 2016 pm 01:22 PM
fgets txt

PHP读取TXT指定行的数据
现在有一个很大的TXT,大小超过了内存的大小(假设哈),
要替换部分文字,
如果直接读取肯定不行,内存不够。
我想了一个办法就是循环读取,
先读取1000行,操作,然后清空变量,循环读取下1000行,
file_get_contents()这个函数好像是一下子读取所有的内容,
不知道有没有其他函数或方法。


------解决方案--------------------
fgets 一次一行
fread 一次一块(指定大小)

如需直接修改源文件,打开时用 r+ 方式
回写时需用 fseek 定位文件指针,偏移用 ftell 取回

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is Intel TXT? What is Intel TXT? Jun 11, 2023 pm 06:57 PM

IntelTXT is a hardware-assisted security technology launched by Intel. It can ensure the integrity and security of the server during startup by establishing a protected space between the CPU and BIOS. The full name of TXT is TrustedExecutionTechnology, which is Trusted Execution Technology. Simply put, TXT is a security technology that provides hardware-level protection to ensure that the server has not been modified by malicious programs or unauthorized software when it is started. this one

How to convert html to txt How to convert html to txt Aug 31, 2023 am 09:23 AM

Methods for converting html to txt include using a text editor, using online conversion tools, and using Python programming. Detailed introduction: 1. To open an HTML file, you can use any text editor, such as Notepad, Sublime Text, etc. To select the content of the entire HTML file, you can press the Ctrl+A shortcut key or drag the mouse to select and copy the selection. The content can be copied by pressing the Ctrl+C shortcut or through the copy option in the right-click menu, opening a new TXT file, using the same text editor, etc.

How to convert chm to txt How to convert chm to txt Oct 17, 2023 pm 02:42 PM

chm is converted to txt by using online conversion tools, using browser plug-ins, using command line tools and using third-party software. Detailed introduction: 1. Use the online conversion tool, just upload the CHM file, select the TXT format, and then download the converted TXT file; 2. Use the browser plug-in, after installing the plug-in, just open the CHM file in the browser, and then Click the plug-in button to convert CHM files into TXT format; 3. Use command line tools, etc.

The reason why php fgets ignores the newline character at the end of the line and its solution The reason why php fgets ignores the newline character at the end of the line and its solution Mar 20, 2023 pm 04:12 PM

PHP is a popular programming language used for developing web applications and dynamic websites. When processing file input, the fgets() function is typically used to read a line of text from a file. However, sometimes the fgets() function ignores newline characters at the end of a line, which can lead to program errors and unpredictable results. In this article, we will explore the causes and solutions to this problem.

FAQ for pandas reading txt files FAQ for pandas reading txt files Jan 19, 2024 am 09:19 AM

Pandas is a data analysis tool for Python, especially suitable for cleaning, processing and analyzing data. During the data analysis process, we often need to read data files in various formats, such as Txt files. However, some problems will be encountered during the specific operation. This article will introduce answers to common questions about reading txt files with pandas and provide corresponding code examples. Question 1: How to read txt file? txt files can be read using the read_csv() function of pandas. This is because

Introduction to PHP functions—fgets(): Read a line from a file Introduction to PHP functions—fgets(): Read a line from a file Jul 24, 2023 pm 12:54 PM

Introduction to PHP functions—fgets(): Read a line from a file In PHP, many functions are provided for reading and writing files. Among them, the fgets() function is one of the functions used to read the content line by line from the file. This article will introduce the fgets() function and demonstrate its usage through code examples. The fgets() function is one of the file input functions in PHP, used to read a line of content from a file. Its basic syntax is as follows: stringfgets(resource$ha

How to convert chm to txt How to convert chm to txt Oct 31, 2023 am 09:35 AM

The steps to convert chm to txt are to prepare tools and environment, open CHM file, export TXT file, edit TXT file, save and close TXT file. Detailed introduction: 1. Prepare tools and environment, prepare CHM reader, text editor and operating system; 2. Open the CHM file and use the CHM reader to open the CHM file you want to convert. In the reader, you can select the file you want to convert. Pages or chapters, some readers may allow the conversion of multiple pages, while others only allow the conversion of a single page; 3. Export TXT files, etc.

Is txt a word document? Is txt a word document? Aug 26, 2022 pm 04:59 PM

txt is not a word document. txt is a text format that mainly stores text information, that is, text information; while Word document is a format of electronic documents (the suffix is ​​doc or docx). How to convert txt to word document: 1. Select the txt file on the desktop, right-click "Rename"; 2. Modify the suffix name format to "doc"; 3. Click "Yes" in the pop-up window box; 4. Double-click Open the file, select the appropriate encoding in the pop-up window, and click "OK" in the lower right corner.

See all articles