tags:

views:

60

answers:

4

I will explain more

I have file called date.php and text file called word.txt. I put more Proverbs in word.txt

Now, every day I need to print one proverb only from word.txt, like this:

  • Saturday prints "A burnt child dreads fire"
  • Sunday prints "no gain without pain"
  • and so on, the proverb will change every day

Can anyone help me with this idea?

A: 

You can read from a file using the file function.
Say you place the new proverb at the top, you can do something like this:

$lines = file('word.txt');
echo $lines[0]; // displays the first line
Alec
ok its works but i need to work per day
magy
+4  A: 

If it's a week rota (i.e. one proverb per weekday), I would do it like this:

$proverbs = array(

  # Monday 
  "Build a man a fire, and he'll be warm for a day.
   Set a man on fire, and he'll be warm for the rest of his life.
   -- Terry Pratchett", 

  # Tuesday
  "The pen is mightier than the sword if the sword is very short,
  and the pen is very sharp
  -- Terry Pratchett",

  # Wednesday
  "....",

  # Thursday
  "...."


  );

  $current_weekday = date("N"); # 1 = Monday ... 7 = Sunday

  echo $proverbs[$current_weekday];
Pekka
but i need it in text not in array
magy
Then load it into an array using php's file functions.
middus
+7  A: 
$proverbs = file('word.txt');
echo $proverbs[(int)date('z')%count($proverbs)];
You
ok its work gooodthank you very much
magy
A: 
    $proverbs = file('word.txt');
    $today = (int)date('N');
    echo $proverbs[$today - 1];

Just put all your proverbs on a new line in the text file.

Jhong