|
Posted by mootmail-googlegroups on 10/28/81 11:57
kulet wrote:
> Hi guys! Got stuck with this..
> I have a chunks of text separated with blanc line. All I need is to
> take every last 3 lines of that text before the blanc line and put it
> in to the new text file: example:
You could keep a rolling buffer of the previous 3 lines as variables
(or an array, which I would personally use). Each time you get a new
line, move each previous entry down the buffer getting rid of the
oldest. Then, when you encounter a blank line, dump your buffer to the
file.
Something like (untested):
$currLine = //get line data somehow
if (strlen($currLine)==0){
//output array contents to file
unset($buffer);
} else {
$buffer[] = $currLine;
if (count($buffer)>3){
array_shift($buffer);
}
}
Navigation:
[Reply to this message]
|