PHP find text line from text date

I am trying to select a text line based on date, I have a text file with this sample data

03/03/2024 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017 France
03/03/2024 07 Prophecy Fulfilled, History Made 2023 (Profecia Cumplida, Historia Hecha) 19-11-2023 Singapore Singapore
03/03/2024 03 Resist the Curse (Resiste la Maldición) 11-12-2022 France
02/03/2024 49 The Father’s Good Pleasure (El Buen Agrado del Padre) 28-1-2024 Germany Karlsruhe Baden-Wurttemberg
01/03/2024 47 The Way to the Father Part 2 (El Camino al Padre) 12-2-2023 Singapore Singapore
01/03/2025 47 The Way to the Father Part 2 (El Camino al Padre) 12-2-2023 Singapore Singapore

I have this code

 $arrlength = count($data);
 
 for($i = 0; $i < $arrlength; $i++){
 $d = intval(substr($data[$i],8,2));
 
 if($d = 24) 
 {
 file_put_contents('/path/to/file_2024.txt', $data[$i]);
   echo "<br>";
 }

 if($d = 25) 
 {
 file_put_contents('/path/tofile_2025.txt', $data[$i]);
 }
   echo "<br>";
 }

I would like the output
01/03/2025 47 The Way to the Father Part 2 (El Camino al Padre) 12-2-2023 Singapore Singapore
to write to a the appropriate text file

One = is an assignment operator. Two == is a comparison operator.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service