Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wrong method?

Featured Replies

For one of my projects, I was told to have a different banner load based on the month of the year. So what I did was this:

$today=date(l); // Find what today is? using date function

//Monthly definitions

if($month==January){
echo "<img src='images/january.png' /><br />January";
}

else($month==February){
echo "<img src='images/february.png' /><br />February";
}

 

Before I submit any of my projects, I have someone review it for me. So for this project, I had a friend of mine look it over, and he said it was improper method to accomplish the job. If that's improper, I am curious to find out what the proper method is. Can anyone help?

lower case L in the format argument for date gives you a textual representation of the day. Upper case F gives the month.

 

I'm not sure if this method will always return an English string - could be a locale setting. Using the numeric format is safer - that's lower case M - gives you a values from 01-12.

 

And your code doesn't seem to have quoted the string values you deal with.

 

You also assign the return value to the variable $today - but you compare later on to a variable $month that doesn't seem set.

 

$month=date('m'); // Find what today is? using date function

//Monthly definitions

if($month=='01'){
echo "<img src='images/january.png' /><br />January";
}

else($month=='02'){
echo "<img src='images/february.png' /><br />February";
}

 

 

Not sure what your friend means by improper - you'd have to ask him about that. But it doesn't look like you tested your code.

Or something like this?:

 

$monthnumber = date('m'); 
$monthname = date("F", mktime(0, 0, 0, $monthnumber, 10)); 
echo '<img src="images/'.strtolower($monthname).'.png" />'.$monthname;

 

That should do it! :hi:

Assuming it will always return English, that would work. But do you have to create a new time object?

 

$monthname = date("F"); 
echo '<img src="images/'.strtolower($monthname).'.png" />'.$monthname;

Good point... I thought using the mktime would be a way to ensure it was in 'English' format - but I'm not anywhere near enough of a PHP expert to know such things!

Assuming settings will return English names then your 2-liner version will work nicely. :D

That'd be easier! :lol:

Or, if you wanted nice names, put the names of the months into an array and just use the month number to return the right one.

  • Author

Oh oops. I honestly don't know what my friend was talking about. He said that I wasn't using a valid call when the script tells the server to get the current date. Well I'm glad to know, I didn't completely screw up my code. Strangely the "l" value does work for me. Or at least I think it did. In anycase, I'll just use the numeric method you guys/girls pointed out. Thanks everyone!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.