From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Inserting the appropriate alt text

Solution: Inserting the appropriate alt text - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Solution: Inserting the appropriate alt text

This is how I solve the challenge of inserting the correct alternate text for the image of the month. When we displayed the image, in the previous chapter, we used the first three letters of the month's name, which were part of the image file name. And the code to do that is on line two. We use the date function and passed it a format string of uppercase M, which gets the first three letters of a month's name. So to solve this particular problem, I went back to the documentation for the date function on the PHP website. And scrolled down, looked at the format characters, and in months, lowercase M gives you a numeric representation of a month without leading zeros. One through 12, so that's what I decided to use. So back in my editor I created a new variable called months number and use the date function with a lower case n as the format string, and then all the text that I'm going to use as the alternate text, I converted into an array and to save time, I'm going to open that from a…

Contents