include() multiple files? (blog script)

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
User avatar
SteveO
Forum Newbie
Posts: 12
Joined: Wed Nov 19, 2003 2:27 am

include() multiple files? (blog script)

Post by SteveO »

FYI i'm like an absolute n00b in programming period, did SOME ASP a while ago, did SOME VB (i know they're pretty much the same) and some Javascript all usually very basic stuff. So bear with me.

I'm trying to make a blog script, that will include each file (03.11.19.php(date YY.MM.DD)) in order... so that I don't have to put them all in a file, i then later i want to have it categorize the blogs per year. which is why i did the filenames the way they are... I'm VERY open to suggestions, I can get this to work with one file, and I know why it doesn't work with two, because it tries to add all the filenames into one var. $file_list But i just can't think of a way to seperate it so that i can load all those files. Thank you all for your time.

Code: Select all

<?PHP
$dir_name = "blogs/";
$dir = opendir($dir_name);
$file_list = "";
$files = "";
while ($file_name = readdir($dir)) &#123;
if (($file_name != ".") && ($file_name != "..")) &#123;
$file_list .= "$file_name";
&#125;
&#125;
$files .= "$dir_name";
$files .= "$file_list";
closedir($dir);
?>
Note: I got this out of PHP fast and easy web development, and so far the book has helped and i havn't finished reading it, but i really want to jump the gun and make this script... So any help is welcome.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

There was a post about this a little while ago. Here is probably a different solution for you. Use scandir. It returns an array of files in a directory. So if you have all your blogs in one directory and nothing else in it this will work fine. I think for ease of use you may want to name the files with a count and date. The date you can use later to sort into years and the count you can use for sequentialisation in your php. So for instance if you anticipated 1000 entries you could use a 3 digit count and today's blog could be 00111192003.php if you are in the US.

http://au2.php.net/manual/en/function.scandir.php

Just my suggestion. Probably an easier way. There usually is. :)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

scandir()? Wouldn't that only work with PHP5? I doubt he would have PHP5 installed, neither his host or localhost. Anyhow, from what you're doing, it's all good. You can use str_replace() to take out the .txt and then use explode() to sort out the date part. Maybe mk_time() for a certain date/time of the file you would want.

But if you want a really effective blog, why not use MySQL? Text files are not that easily manageable nor editable. Well, uploading and replacing would do but most of the time, we build entire backend systems for a blog/news site.

-Nay
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Hmmm...I was wondering why I hadn't seen this nifty tool before. :oops:
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

haha, it will be soon. Be sure to check right at the top of the notes which version of PHP the specific function works under next time. I was scratching my head over why $_POST['me'] or $me both works on PHP until I saw that my version had register_globals turned on.

Well, memories..........YES, that WAS a long time ago :lol:

-Nay
User avatar
SteveO
Forum Newbie
Posts: 12
Joined: Wed Nov 19, 2003 2:27 am

Post by SteveO »

well the reason why i didn't want to use MySQL was because i don't seem to have permissions to create new DBs on my server... which sucks... so, i pretty much wanted to go around that.
Post Reply