News page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bw
Forum Newbie
Posts: 3
Joined: Tue Aug 26, 2003 3:51 pm

News page

Post by bw »

Hey all,

I have a news page on my site, and it is fed by a .inc with the news articles contained in it.

How would I go about perhaps reading the file backwards for updating the page with multiple entries?

Or is there a way to write to the file in front of the data all ready there, and still keep that data?

I use a self developed system for updating the news, and it need so be ble to achieve this all automatically.

Thanks for any help,
Ben
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You could, read a file using file(). The content is then inserted into an array (one row / key). array_reverse() that, and you have the opposite direction...

Code: Select all

Array
(
    [0] => 1: I'm a foo...
    [1] => 2: phpdn test...
)
Array
(
    [0] => 2: phpdn test...
    [1] => 1: I'm a foo...

)

1: I'm a foo...
2: phpdn test...

<pre>
<?php 
    $array = file('info.inc');
    print_r($array);
    $array = array_reverse($array);
    print_r($array);
    show_source('info.inc');
    show_source(__FILE__);
?>
Post Reply