AdonaiEchad wrote:
> I am trying to get my php script to say Good morning and
then Good afternoon
> using military time. I can't see to get the script to
run properly. Here is
> what I have, what am I missing.
There are many mistakes in that script. First of all, if
you're
assigning date("G") to a variable ($today), you should be
using the
variable instead of constantly repeating it. Secondly, you
cannot use
comparisons in a case expression. Only integers,
floating-point numbers,
or strings are allowed. Thirdly, even if your switch
statement worked
(which it won't), you have omitted break after the second
case expression.
http://www.php.net/manual/en/control-structures.switch.php
The solution that Gary has given you is the shortest, but may
not be
quite so easy to read if you're not familiar with the
conditional operator.
This might be easier to read:
<?php
$hour = date('G');
if ($hour < 12) {
$greeting = 'morning';
}
elseif ($hour < 18) {
$greeting = 'afternoon';
}
else {
$greeting = 'evening';
}
echo "Good $greeting";
?>
--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/