Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Daily Script

Links for php scripts

Moderators: macek, egami, gesf

Daily Script

Postby TheBoss » Thu May 31, 2012 10:28 am

Hi,

I would like to able to add a script on my webpage that displays a fact every 24 hours. I know there are quite a few of these when searching, but they do not deal with what I want.

I want a script that reads the current date in a text file and displays the fact associated with it.

In the text file, it would be displayed like this:

31/05/2012 This is the fact 1
01/06/2012 This is the fact 2
02/06/2012 This is the fact 3
03/06/2012 This is the fact 4

I would have a fact for every day.

Is this possible ?

Thanks
TheBoss
TheBoss
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu May 31, 2012 10:20 am

Re: Daily Script

Postby Nullsig » Thu May 31, 2012 11:04 am

Yes but you will need to format your text file slightly different

Code: Select all
31/05/2012|This is the fact 1
01/06/2012|This is the fact 2
02/06/2012|This is the fact 3
03/06/2012|This is the fact 4


Once you have formatted the file like this you just read line by line and explode each line on the "|". Then compare the first element of the exploded line with the current date (formatted using d-m-Y) and if there is a match you display the second element of the line.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Daily Script

Postby TheBoss » Thu May 31, 2012 11:10 am

I am new to this php and understand very little how to code this type of script.
TheBoss
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu May 31, 2012 10:20 am

Re: Daily Script

Postby Nullsig » Thu May 31, 2012 11:37 am

You won't really learn much with me handing you the script either though....

Read up on these functions (use php.net):
fopen - used to open files
explode - used to turn strings into arrays using a separator
date - generates a formatted date according to given format
strtotime - takes a given string and returns number of seconds since epoch
fgets - grabs a line of text from an open file
echo - outputs text to the browser
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Daily Script

Postby HopelessCode » Tue Jun 19, 2012 10:06 am

Um. Why not just check it with a cronjob, and then retrieve a quote from a mysql database, cache the result and boom?
HopelessCode
New php-forum User
New php-forum User
 
Posts: 5
Joined: Mon Jun 18, 2012 7:57 am


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron