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.
Finding and extracting a substring - PHP Tutorial
From the course: PHP for Web Designers
Finding and extracting a substring
The plan for processing the data from the Build a Bouquet form in the Hansel and Petal site, involves identifying whether an array key begins with a known prefix, and stripping it off. Before diving into the code, let's take a look at how to find and extract a substring. In this exercise file, one of the array keys we'll be working with has been assigned to a variable called original. On line two. What we need to do is to find out whether it begins with color_, color underscore and if it does extract the final part, in this case calla lillies the name of the flower. So, to find the position of a substring within another string you use a function which has an impossible name. Strpos, which stands for string position. And it takes two arguments. The first one is the string that you want to search, and the second is the substring that you're looking for. So let's try that out. On line 14, I'm going to add a PHP block. And we want to display the results of strpos, so it will be echo and…
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)
Getting form input sent by the POST method4m 48s
-
Retrieving values from a URL's query string4m 8s
-
(Locked)
Challenge: Plan the order form2m 28s
-
(Locked)
Solution: Plan the order form4m 42s
-
(Locked)
Finding and extracting a substring7m 38s
-
(Locked)
Organizing the form data into arrays7m 15s
-
(Locked)
Using a loop to build a table for the data4m 42s
-
(Locked)
Controlling which rows are displayed7m 45s
-
(Locked)
Creating a custom function to extract part of a file name7m 43s
-
(Locked)
Calculating the order total6m 34s
-
(Locked)
Using PHP sessions to preserve data3m 14s
-
(Locked)
Storing data in session variables7m 33s
-
(Locked)
Ending the PHP session and deleting the data5m 37s
-
(Locked)
-
-
-