|
-
Mar 4th, 2005, 11:51 PM
#1
Thread Starter
Hyperactive Member
what is it doing
im trying to learn php and i came across this sample code
Code:
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>
</body>
</html>
what is the line "$d=date("D");" doing and why is it not setting a value of fri or something
It's not just Good, It's Good enough!
Spelling Eludes Me
-
Mar 5th, 2005, 03:37 AM
#2
Re: what is it doing
That is a very poor example. I would actually re-write it to the following:
PHP Code:
<html>
<head>
</head>
<body>
<p>
<?php
$d=date("D");
if ($d=="Fri") {
echo ("Have a nice weekend!");
} else {
echo "Have a nice day!";
}
?>
</p>
</body>
</html>
All I've done is indented the code and made sure the HTML was correct but these are important habbits to get into if you are learning.
The $d=date("D"); line assigns thee return value from calling PHP's date() function to the variable $d. The string "D" is the format in which the date can be return and on PHP.Net it explains:
D A textual representation of a day, three letters Mon through Sun
Therefore it will return either Mon,Tue,Wed,Thu,Fri,Sat or Sun depending on the day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|