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 - PHP Tutorial
From the course: PHP for Web Designers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Storing multiple values in a variable as an array4m 28s
-
(Locked)
Inspecting an array's elements4m 13s
-
(Locked)
Challenge: Inserting the appropriate alt text1m 27s
-
(Locked)
Solution: Inserting the appropriate alt text5m 26s
-
(Locked)
Displaying an array as a comma-separated list3m 13s
-
(Locked)
Looping through an array's values7m 17s
-
(Locked)
Labeling array elements7m 21s
-
(Locked)
Looping through an array's labels and values5m 29s
-
Finding if a value exists in an array3m 51s
-
(Locked)
Challenge: Displaying a seasonal feature3m 6s
-
(Locked)
Solution: Displaying a seasonal feature8m 30s
-
(Locked)
-
-
-
-