Current location: Hot Scripts Forums » Programming Languages » PHP » display text depending on day


display text depending on day

Reply
  #1 (permalink)  
Old 05-23-05, 12:48 PM
ancdy ancdy is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
display text depending on day

how do i make a piece of code which displays certain text (defined by me in the code) depending on the day of the week.
So for example;

on monday: today is monday
on tuesday: welcome, it's tuesday
.
.
.
on saturday: it's sunday today

Please help
Reply With Quote
  #2 (permalink)  
Old 05-23-05, 01:12 PM
robbydweb robbydweb is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
You can use the date function

PHP Code:

if(date("l") == "Monday") echo "Today is monday";

elseif(
date("l") == "Tuesday") echo "Today is tuesday";
elseif(
date("l") == "Wednesday") echo "hi its wednesday"
// ect.. 
Reply With Quote
  #3 (permalink)  
Old 05-23-05, 04:01 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
I would do like this:

$captions = array(
1=>'Hello, it\'s Monday',
2=>'Ok, Tuesday',
3=>'Still Wednesday',
4=>'Already Thursday'
5=>'Now it\'s Friday',
6=>'Saturday, party time!',
7=>'Ohh, Sunday');

and then just echo $captions[$dayOfWeek]
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #4 (permalink)  
Old 05-23-05, 05:51 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
slight problem though, you havent set the $dayOfWeek variable i wud use:

PHP Code:

<?php


$day 
date("l");

if (
$day == "Monday") {
echo 
"today is monday";
}
elseif (
$day == "Tuesday") {
echo 
"today is tuesday";
}
elseif (
$day == "Wednesday") {
echo 
"today is wednesday";
}
elseif (
$day == "Thursday") {
echo 
"today is thursday";
}
elseif (
$day == "Friday") {
echo 
"today is friday";
}
elseif (
$day == "Saturday") {
echo 
"today is saturday";
}
elseif (
$day == "Sunday") {
echo 
"today is sunday";
}
else {
echo 
"PHP Error: Cannot determine day comment...";
}

?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #5 (permalink)  
Old 05-24-05, 03:28 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

Just to add to dennispopel'x post.


PHP Code:

// 'w' param gets you a zero-based numerical index for the day of a week, starting Sunday.

// Therefore, if you want to use this with dennispopel's array,
// Sunday should be indexed with 0 (zero), instead of 7.
$dayOfWeek date('w'); 
My 2 cents.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you display a query in a text box? jozin PHP 4 05-10-05 06:52 AM
Display records in a text box bartbauldry ASP 1 01-16-05 09:30 PM
MySQL Query problem Wraith PHP 5 03-06-04 05:16 PM
Directory Contents (Images & text) Display Script. gsb Script Requests 0 02-23-04 07:33 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 06:46 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.