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

Creating a custom function to extract part of a file name - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

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…

Contents