Re: News system in one file _or_ how to read lines from a file
| From: | Jason Lavigne | Date: | Fri, 01 Dec 2000 02:56:41 +0000 |
| Subject: | Re: News system in one file _or_ how to read lines from a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28051@lists.php.net to get a copy of this message | ||
OK, got you. The easiest way would be to read the file in to an array (fopen
and fread), the go through each line one by one, then if your current line
is "<item>" then the next is one that needs to be exploded. This would be
the easiest way. Here is a quick example, the code may not be correct:
$my_news_file = the file as an array.
for ($j = 0; $j < count($my_news_file); $j++) {
if ($my_news_file[$j] == "<item>") {
$not_done = 1;
for ($line = 1; $not_done; $line++) {
if (($my_news_file[$j + $line] == "<item>") || ($line >
count($my_news_file)) {
// this is saying that if the next line is item again, quit
this loop
// or if it is the end of file also quit.
$not_done = 0;
} else {
$good_line = $my_news_file[$j + $line];
// now $good_line contains "title....|date|author"
// The code will stay in here for each line until it either
// finds a new <item> or it is the end of the file
// You can do what ever you need to here :)
}
}
}
Did this help any?
Jay
----- Original Message -----
From: "Jesus Climent" <climent@stybba.ntc.nokia.com>
To: "ext Jason Lavigne" <jlavigne@stonecroft.net>
Cc: "Jesus Climent" <climent@stybba.ntc.nokia.com>;
<php-general@lists.php.net>
Sent: Thursday, November 30, 2000 9:44 AM
Subject: Re: [PHP] News system in one file _or_ how to read lines from a
file
> On Thu, 30 Nov 2000, ext Jason Lavigne wrote:
>
> > > The format of the file is:
> > >
> > > <item>
> > > title....|date|author
> > > text
> > >
> > > <item>
> > > ....
> > >
> > >
> > > and so on.
> > >
> > > I want a piece of code that reads the very first line after <item> and
> > > data=explodes ("|" , 1st_line), uses data[1], data[2] and data[3] to
set
> > > the table structure and reads the rest of the text as the news itself.
> > >
> > > until it arrives to next item... and repeats again till the end of the
> > > file.
> > >
> > > Any help?
>
> How can i read just the 1st line after every <item>?
>
> How can I count the number of <items> to use in if{} statements?
>
> daTa
>