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 frothpoker on 09/26/20 11:57

Messy but effective:-

Read the whole of the text into a variable.

Reverse the string. I dont know if there is a function to do this or
whether you would have to write one.

copy the first three lines after each paragraph to a new variable.

Reverse this string to get it back into the correct direction.

OR:

more effective.

Copy the whole text to a variable
Split it at CRLF into an array.
The blank lines should create an 'empty' array element
For each array element, check the next three elements and if any of
them are empty (not sure if it will be null or just length zero) then
add it to a variable.

return the variable.

easy.

Aaron
mootmail-googlegroups@yahoo.com wrote:
> 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

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