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:
1some text
2some text
3some text
4some text
5some text
6some text
7some text
8some text
9some text
10some text
11some text
12some text
13some text
14some text
15some text
End result mast be...
3some text
4some text
5some text
8some text
9some text
10some text
13some text
14some text
15some text
Any idea?
Hi,
That is easy. You must replace all double newlines with 1 newline.
But beware: you say 'blanc line', but you must first find out how that is
coded in your file.
Often a newline is \n but sometimes it is \n\f or something like that.
(\f for linefeed)
It is also implemented differently on Unix, Windows, and Mac, just to make
your life misserable.
So you need something like this:
$newLineOnMySystem = "\n";
$yourString = "sometextsometextetcetc";
// Now replace all double occurences with single ones.
$yourString = str_replace($newLineOnMySystem.$newLineOnMySystem ,
$newLineOnMySystem, $yourString);
Read more here about string replacement:
http://nl3.php.net/manual/en/function.str-replace.php
But first find out what character(s) define newline on your system.
If uncertain try this:
You can use the function ord() to get the ascii value of a character.
Just print them out once for all characters in your file, and see what your
newline is.
More here:
http://nl3.php.net/manual/en/function.ord.php
Regards,
Erwin Moller