Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

A question about PHP


KoE

Recommended Posts

I was wondering if its possible to load a series of external text files into a web page using PHP.

What I'm hoping to achieve is something where text files are loaded in date order, (latest to oldest) to appear on the page as news items.

for example:

  • 14/8/07
  • 13/8/07
  • 12/8/07

Is this possible without the use of SQL?

As always any help is much appreciated.

EDIT:

I am aware that there are various blog styled scripts that can be obtained off the internet, but I am aiming for something very simple, without all the junk.

Link to comment
Share on other sites

I would be having the file names as dates most likely, as that seems most appropriate, and easiest to order

for example something along the lines of:

  • 12/08/07 = 120807.php
  • 15/09/08 = 150908.php

however the values here clearly would have problems when ordering them.

I'm sure there are better ways of naming them by date, so that it would actually work efficiently.

Link to comment
Share on other sites

Not sure why there's a separate PHP file for each date...

Anyway, a single PHP file could be used to load the last X files starting at a certain date (default to the current date). It will get a tad unwieldy when you have LOTS of files, but it's doable.

The "smart" way to do it, if you don't want to use SQL, is to make your own type of automated filing system (requires ability for scripts to write to files). This would keep a separate data file with a list of files in chronological order, so you can load the list of files without enumerating the entire directory and sorting them. The script would have an interface for editing the news files as well, meaning the script would name, save and index each news item for consistency.

Is that a solution you'd be interested in?

=Smidge=

Link to comment
Share on other sites

I see where your coming from, although the idea was to keep it simple using external text files for news items, that could be loaded into the page.

What are suggesting is more along the lines of something such as the CuteNews script i think. Correct me if I'm misunderstanding.

However if it comes down to it, I may attempt this approach, as doing it my theoretical way, may make things more complicated than necessary.

Link to comment
Share on other sites

Instead of storing it with numerical dates sans punctuation, use timestamps. This can be done using the time() and date() functions. That way you won't have confusion with 10607 being 1-06-07 or 10-6-07 or anything like that. Time stamps are unique for each second! Woo.

Here's a method I'll just cook up off the top of my head.

  • First of all, I assume you know how to use substrings and string functions to manipulate and pull data from text. Come up with some arbitrary substrings like DATE:, SUBJ:, and BODY: for actual fields in the news post. Come up with another substring like =ENDPOST= to determine where your posts end in your file.
  • When you add a news post, add it to the beginning of your news text file. Using a single text file will be easier in the long run.
  • Format your news in the file something like this:
    DATE:[timestamp of whatever time it is]
    SUBJ:Test
    BODY:Hello World!
    =ENDPOST=[/CODE]


    What this achieves is that you can still edit the raw text data in a single file, and it looks decent and simple to your eye.

  • When you're trying to pull news back out, use the explode() function to separate each separate post into an array. Traverse the array and use string functions to pull the DATE, SUBJ, and BODY fields into their own respective keys. When you're done, you should have a two-dimensional array of all of the posts.
  • Regurgitate the data how you see fit.

Tell me if you need any more help.

Link to comment
Share on other sites

Well I'm trying to test new ideas and generally improve my current web coding habits. This was just something I thought could be useful for me to learn for future use and reference.

Thanks to Smidge and Sage for the suggestions, they are much appreciated.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...