From the course: Learning the Standard PHP Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Extending FilterIterator to create a reusable filter - PHP Tutorial
From the course: Learning the Standard PHP Library
Extending FilterIterator to create a reusable filter
- Filter Iterator is different from most of the SPL Iterators in that you can't create an instance of Filter Iterator itself. It's an abstract class. So, you have to create your own class and extant the Filter Iterator class. To show you how to use it, I'm going to be using the same basic simple XML to extract data from courses.XML that I've used in other videos in this chapter. You can find a copy of this file filter.php in the Chapter 3 folder of the exercise files. Normally, it's considered best practice to create class definitions in a separate file, but for the purposes for this demonstration, I'm going to create it at the top of this page here. So, I'm going to add in a few extra lines. I'm going to create a class that will filter the XML by author. So, class. We'll call it Author Filter, and it extends Filter Iterator. We'll begin by creating a protective property to store the authors name. Normally, the only method you need to define in the classes extend Filter Iterator is 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)
Filtering a directory with GlobIterator5m 14s
-
(Locked)
Using regular expressions to filter directories with RegexIterator3m 49s
-
(Locked)
Extracting data from XML with RegexIterator and SimpleXML6m 25s
-
(Locked)
Specifying a range of items with LimitIterator4m 21s
-
(Locked)
Creating a custom filter with CallbackFilterIterator5m 6s
-
(Locked)
Creating a recursive callback filter5m 42s
-
(Locked)
Extending FilterIterator to create a reusable filter5m 10s
-
(Locked)
Creating a custom filter with RecursiveFilterIterator4m 48s
-
(Locked)
Overriding the RecursiveFilterIterator constructor5m 16s
-
(Locked)
Using ParentIterator to find elements that have children3m 59s
-
(Locked)
-
-
-
-
-