Jump to content

new message every day


grucker

Recommended Posts

I have had a different message appearing evry day based on the name of the day. I now want a message based on the date up to 31. I have tried messing to no no avail. Help will be appreciated

 

 

$day_post = "includes/days";
 
$today = date('l');
if (file_exists($day_post."/".$today.".php"))
    {   
    /**echo "$day_post/".$today.".php"; **/
include("$day_post/".$today.".php");
    } else {   
    echo "No thoughts came into my head $today";
}
 

Link to comment
https://forums.phpfreaks.com/topic/284120-new-message-every-day/
Share on other sites

  On 11/20/2013 at 10:48 PM, requinix said:

Have you already (re)named the files?

 

$today = date('l');
That's what it uses to determine the name of the file. Check the documentation to see how to make it return a day number instead of a weekday name.

 

I renamed the files 1.php 2.php etc. but the else message came up. I tried the various other letters in the code you advised but the else message still came up with the name of todays day i.e. Thursday so it doesnt seem to have changed anything. I even cleared the letter from the parentheses so it was $today = date(''); and the day name still came up. Could you give more advice please.

Have you tried using a root-relative link? For example, you could try something like:

$day_post = "{$_SERVER['DOCUMENT_ROOT']}/includes/days";

Of course, you may need to adapt the path which comes after the SERVER variable. More information about the SERVER variable can be found here:

http://php.net/manual/en/reserved.variables.server.php

  On 11/21/2013 at 1:41 PM, cyberRobot said:

Have you tried using a root-relative link? For example, you could try something like:

$day_post = "{$_SERVER['DOCUMENT_ROOT']}/includes/days";

Of course, you may need to adapt the path which comes after the SERVER variable. More information about the SERVER variable can be found here:

http://php.net/manual/en/reserved.variables.server.php

Dont think its that. When I called the files monday etc. and asked for the daily message everything worked fine. Renaming the fies to 1, 2 3 etc. and calling the month day number results in error message but for the day in question. So no wiser.

the files are 1 through 31 .php

 

<?php // Change $day_images to the location of images
$day_post = "includes/days";
 
$today = date('');
if (file_exists($day_post."/".$today.".php"))
    {   
    /**echo "$day_post/".$today.".php"; **/
include("$day_post/".$today.".php");
    } else {   
    echo "No thoughts came into my head $today";
}
?>
  On 11/22/2013 at 12:03 AM, cyberRobot said:

I think the issue is that you were originally passing 'l' to the date function which gives you a value from "Sunday" through "Saturday". Have you tried "j"?

$today = date('j');

That gives you the day of the month 1 to 31.

Thank you ever so much that is the answer

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.