Re: PERL to PHP

From: Date: Tue, 27 Feb 2001 00:40:14 +0000
Subject: Re: PERL to PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41771@lists.php.net to get a copy of this message
On Tue, 27 Feb 2001 01:28, Clayton Dukes wrote: > > Hi :-) > Can someone tell me how to do the equivalant of this Perl script in > PHP? > > ### > ### This function prints all lines between the dashes read in a text > file ### > ### The file looks like this: > > # ----------------------------- > # Somedata: something > # Someother: something else > # ------------------------------ > # > # Several paragraphs > # Several paragraphs > # Several paragraphs > # ----------END-------------- > # > > > > #!/usr/bin/perl -w > @rray = <STDIN>; > > > $inside = 0; > foreach $line (@rray) { > if ($line =~ /-----/ig) { > $inside = 1; > } elsif ($line =~ /-----/gi) { > $inside = 0; > } > > if ($inside == 1) { > print $line; > } > } > > > TIA! Seems like your solution boils down to this: Set toggle = 0 open file for read while not EOF Read file line by line if(line has dashes) toggle = not(toggle) // flip the toggle endif if (toggle) print line endif endwhile close file The code is left as an exercise for the student :-) Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#41771) next »