# PHP find text line from text date

**URL:** <https://www.phphelp.com/t/php-find-text-line-from-text-date/36078>\
**Category:** Uncategorized\
**Created:** [March 17, 2024, 9:01pm UTC](https://www.phphelp.com/t/php-find-text-line-from-text-date/36078 "2024-03-17T21:01:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![increase](https://www.phphelp.com/letter_avatar_proxy/v4/letter/i/edb3f5/32.png) [@increase](https://www.phphelp.com/u/increase)\
**Post date:** [March 17, 2024, 9:01pm UTC](https://www.phphelp.com/t/php-find-text-line-from-text-date/36078/1 "2024-03-17T21:01:08Z")

</div>

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

```auto
 $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

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [March 18, 2024, 1:36am UTC](https://www.phphelp.com/t/php-find-text-line-from-text-date/36078/2 "2024-03-18T01:36:02Z")

</div>

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