Quote for each day

I need your help to change the following code to a better PHP format.

The purpose of this script is to display the daily quote of that particular day.

Thanks in advance!

<? $today = date('D'); $sunday = "The remarkable thing we have is a choice every day regarding the attitude we will embrace for that day. We cannot change our past… We cannot change the fact that people will act in a certain way. We cannot change the inevitable. The only thing we can do is play on the one string we have, and that is our attitude.
- Charles Swindoll"; $monday = "People with goals succeed because they know where they’re going.
- Earl Nightingale"; $tuesday = "The competitor to be feared is one who never bothers about you at all, but goes on making his own business better all the time.
- Henry Ford"; $wednesday = "The key is not to prioritize what’s on your schedule, but to schedule your priorities.
Stephen Covey"; $thursday = "The aim of marketing is to know and understand the customer so well the product or service fits him and sells itself.
-Peter Drucker"; $friday = "Patience and perseverance have a magical effect before which difficulties disappear and obstacles vanish. A little knowledge that acts is worth infinitely more than much knowledge that is idle.
John Quincy Adams"; $saturday = "One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man.
Elbert Hubbard"; if($today == "Sun"){ echo $sunday; } if($today == "Mon"){ echo $monday; } if($today == "Tue"){ echo $tuesday; } if($today == "Wed"){ echo $wednesday; } if($today == "Thu"){ echo $thursday; } if($today == "Fri"){ echo $friday; } if($today == "Sat"){ echo $saturday; } ?>

Is there something wrong with the code or do you just want something more flexible?

You could use an array instead.

[php]
$quotes = array
(
‘Sun’ => “The remarkable thing we have is a choice every day regarding the attitude we will embrace for that day. We cannot change our past… We cannot change the fact that people will act in a certain way. We cannot change the inevitable. The only thing we can do is play on the one string we have, and that is our attitude.
- Charles Swindoll”,
‘Mon’ => “People with goals succeed because they know where they’re going.
- Earl Nightingale”,
‘Tue’ => “The competitor to be feared is one who never bothers about you at all, but goes on making his own business better all the time.
- Henry Ford”,
‘Wed’ => “The key is not to prioritize what’s on your schedule, but to schedule your priorities.
Stephen Covey”,
‘Thu’ => “The aim of marketing is to know and understand the customer so well the product or service fits him and sells itself.
-Peter Drucker”,
‘Fri’ => “Patience and perseverance have a magical effect before which difficulties disappear and obstacles vanish. A little knowledge that acts is worth infinitely more than much knowledge that is idle.
John Quincy Adams”,
‘Sat’ => “One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man.
Elbert Hubbard”
);

$dow = date(‘D’);
echo $quotes[$dow];
[/php]

Then you could take it a step further and have random quotes for each day of week…

[php]
$quotes = array(
‘Sun’ => array(
“The remarkable thing we have is a choice every day regarding the attitude we will embrace for that day. We cannot change our past… We cannot change the fact that people will act in a certain way. We cannot change the inevitable. The only thing we can do is play on the one string we have, and that is our attitude.
- Charles Swindoll”,
“Sun Quote 2”,
“Sun Quote 3”
),
‘Mon’ => array(
“People with goals succeed because they know where they’re going.
- Earl Nightingale”,
“Mon Quote 2”,
“Mon Quote 3”
),
‘Tue’ => array(
“The competitor to be feared is one who never bothers about you at all, but goes on making his own business better all the time.
- Henry Ford”,
“Tue Quote 2”,
“Tue Quote 3”
),
‘Wed’ => array(
“The key is not to prioritize what’s on your schedule, but to schedule your priorities.
Stephen Covey”,
“Wed Quote 2”,
“Wed Quote 3”
),
‘Thu’ => array(
“The aim of marketing is to know and understand the customer so well the product or service fits him and sells itself.
-Peter Drucker”,
“Thu Quote 2”,
“Thu Quote 3”
),
‘Fri’ => array(
“Patience and perseverance have a magical effect before which difficulties disappear and obstacles vanish. A little knowledge that acts is worth infinitely more than much knowledge that is idle.
John Quincy Adams”,
“Fri Quote 2”,
“Fri Quote 3”
),
‘Sat’ => array(
“One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man.
Elbert Hubbard”,
“Sat Quote 2”,
“Sat Quote 3”
)
);

$dow = date(‘D’);
$dow_quotes = $quotes[$dow];
$random_key = rand(0, (count($dow_quotes) - 1));
echo $dow_quotes[$random_key];
[/php]

Thanks m@tt for both possibilities.

Sponsor our Newsletter | Privacy Policy | Terms of Service