Computing.Net > Forums > Web Development > Read a file per month

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Read a file per month

Reply to Message Icon

Name: wearebusiness
Date: November 26, 2005 at 08:33:10 Pacific
OS: Apache
CPU/Ram: ?
Comment:

I want to read our tips and only show one per month. I was hoping to find a script that would read a file in Jan and a differant one in Feb. That way I could right all of my tips at the beginning of the year and the page would automatically update. Does any one know of a place to get such a script?



Sponsored Link
Ads by Google

Response Number 1
Name: haity
Date: November 27, 2005 at 19:29:52 Pacific
Reply:

I need the script too.
Thanks!


0

Response Number 2
Name: FishMonger
Date: November 28, 2005 at 12:21:18 Pacific
Reply:

I doubt that you'll be able to find a pre-written script, but it's fairly easy to write it. What language do you work with, php, asp, perl?


0

Response Number 3
Name: jake1025
Date: November 29, 2005 at 19:20:36 Pacific
Reply:

in php, the code would look something like this:

if(date("n")==1){
$fp=fopen("jan.tip", "r");
print fread($fp, filesize("jan.tip"));
fclose($fp);
}else
if(date("n")==2){
$fp=fopen("feb.tip", "r");
print fread($fp, filesize("feb.tip"));
fclose($fp);
}else
if(date("n")==3){
$fp=fopen("mar.tip", "r");
print fread($fp, filesize("mar.tip"));
fclose($fp);
}else
....


-jake


0

Response Number 4
Name: FishMonger
Date: November 29, 2005 at 21:41:05 Pacific
Reply:

If the “tips” files are named properly, either by month number or name, you can easily with only a couple lines open, read, and print the current month's tips file.

#!/usr/bin/perl -w

use strict;
use POSIX;

# abbreviated month name e.g. Nov
my $month = strftime("%m", localtime);

# month as a decimal number
#my $month = strftime("%b", localtime);

open (TIPS, $month) or die $!;
while (<TIPS>) { print; }
close TIPS;


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


logout or logoff issue One menu on every page



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Read a file per month

Downloading a file from mysql www.computing.net/answers/webdevel/downloading-a-file-from-mysql/2373.html

HTML link to a file in the users PC www.computing.net/answers/webdevel/html-link-to-a-file-in-the-users-pc/2942.html

Getting third line from file www.computing.net/answers/webdevel/getting-third-line-from-file/2416.html