General Community > Scripting Help
noob php question
ApplianceJunk:
I want to learn PHP as i have a mod in mind and feel it would just be a good thing to know.
I'm working through the lessons at this site.
http://w3schools.com/php/default.asp
I did not get far before I had trouble understanding something. ;)
At this page...
http://w3schools.com/php/php_if_else.asp
they give this code at the bottom as a example.
--- Code: ---<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
</body>
</html>
--- End code ---
I want to make sure I understand each lesson 100% before I move on. I have played around with the code in MAMP using my editor.
The one thing I feel I don't really understand is this...
--- Code: ---date("D")
--- End code ---
Is that something that's built into php or what?
Any addition info you could give me would be greatly appreciated.
Thanks,
MrPhil:
date() is a built-in function. See http://us3.php.net/manual/en/function.date.php . That URL should be stamped on your forehead if you're going to do any PHP work. "D" says "return the three letter day of the week".
ApplianceJunk:
Yes, now I understand, thanks!
I had just found this before reading your reply.
http://w3schools.com/php/php_ref_date.asp
--- Quote ---date() Formats a local time/date
--- End quote ---
But I was still left with the question of what "D" was doing.
After reading your reply it all makes sense now.
The link you posted was very helpful, thanks again.
phantomm:
--- Quote from: ApplianceJunk on May 27, 2012, 02:40:52 PM ---But I was still left with the question of what "D" was doing.
--- End quote ---
quote from http://w3schools.com/php/func_date_date.asp:
--- Quote ---D - A textual representation of a day (three letters)
--- End quote ---
That's why you check in if:
--- Quote ---if ($d=="Fri")
--- End quote ---
or
--- Quote ---elseif ($d=="Sun")
--- End quote ---
:)
The Craw:
W3Schools really isn't the best tutorial site IMO. A lot of their code examples are not good, so they're more or less encouraging "bad practice". Tizag is slightly better. The PHP manual itself is the best, albeit slightly factual. Reading the comments in the PHP manual is often helpful.
Good: http://www.w3schools.com/
Better: http://tizag.com/
Best: http://www.php.net/manual/en/langref.php
Navigation
[0] Message Index
[#] Next page
Go to full version