You are here: Re: Any idea how to do this? « PHP Programming Language « IT news, forums, messages
Re: Any idea how to do this?

Posted by Erwin Moller on 12/08/28 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:
>
> 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

 

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

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