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.
Creating a custom function to extract part of a file name - PHP Tutorial
From the course: PHP for Web Designers
Creating a custom function to extract part of a file name
In the Build-a-Bouquet page of the hansel and petal site some flowers are available in a choice of colors. And the name of the color is embedded in the image file name. So, when I selected a yellow color lilly, I got a yellow image here. But I still need to have the color displayed here. We need to extract that from the file name. So, let's see how the file names are structured? Let's go to the editing program. And here we are in bouquet.php, and this is the select menu for calla lilies. And the value for each option is the file name. And it always begins with a number, an underscore, a name, an underscore, and the color. Number, underscore, name, underscore, color. So we've got this pattern, and it runs all the way through the page. Always the same. The color is the third element. We need to treat this like an array. And there's a very useful function, that will split a string into an array, and that is called explode. So, we'll use that to create our own little custom function, to…
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
-
-
-
-
-
-
-
Getting form input sent by the POST method4m 48s
-
Retrieving values from a URL's query string4m 8s
-
Challenge: Plan the order form2m 28s
-
Solution: Plan the order form4m 42s
-
Finding and extracting a substring7m 38s
-
Organizing the form data into arrays7m 15s
-
Using a loop to build a table for the data4m 42s
-
Controlling which rows are displayed7m 45s
-
Creating a custom function to extract part of a file name7m 43s
-
Calculating the order total6m 34s
-
Using PHP sessions to preserve data3m 14s
-
Storing data in session variables7m 33s
-
Ending the PHP session and deleting the data5m 37s
-
-
-
-