preg match - read a file from a specific line php -


i try read specific lines in text file.

my text file :

# #  aliases in file not expanded in header #  mail, visible on networks or /bin/mail.  # basic system aliases -- these must present. mailer-daemon:  postmaster postmaster:     root  # general redirections pseudo accounts. bin:            root nscd:           root pcap:           root apache:         root webalizer:      root  # boite fonctionnelles # gemel accueil:        demo1,demo2 services:       demo3,demo4 essai:          dan.y.roche@gmail.com 

i want collect line rework them after:

accueil:        demo1,demo2 services:       demo3,demo4 essai:          dan.y.roche@gmail.com 

i can find lines comment : # gemel

we can :

if($lines = file($filename)){      foreach ($lines $key => $value) {         if(preg_match("/# gemel/", $value))             ($i=0; $i < ; $i++) {                  # code...             }   }  } 

but it's not double tab... solution move pointer after find # gemel how can ?

just 1 dimensional loop:

$resultlines = array(); $save = false;  foreach ((array)file($filename) $key => $value) {     if (preg_match("/# gemel/", $value)) {         $save = true;         continue;     }      if ($save) {         $resultlines[] = $value;     } }  var_dump($resultlines); 

requires after #gemel comment relevant lines exist. if not true, check next comment, , set $save again false.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -