Delete lines after fgets () if condition is met in php

I have a very large text file, I use fgets () to get the contents of the file line by line. but I need to delete some text from the file if a certain condition is met.

Example:

hello world am string number 1 hello world am string number 2

hello world am string A hello world am string B

lets say that the condition occurs on line 1, then I want to delete lines 1 and 2, but I do nothing for lines A and B

+2
source share
1 answer
  • Open this very large text file for reading. Call this file 1.
  • Open a new file for writing. Call this file 2.
  • Read the line from file 1.
  • Check if the line meets your requirements.
  • , 2.
  • , .
  • 1. , , .
  • , 1 2 1. (, , , !)
+7

Source: https://habr.com/ru/post/1772226/


All Articles