You are here: Re: Hi guys! Got stuck with this.. « PHP Programming Language « IT news, forums, messages
Re: Hi guys! Got stuck with this..

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация