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.
Specifying a range of items with LimitIterator - PHP Tutorial
From the course: Learning the Standard PHP Library
Specifying a range of items with LimitIterator
- I've got open limit.php, which loads courses.xml in the common data directory as simple XML and then displays the title, author and duration of each course. You can find a copy of this file in the chapter three folder of the exercise files. If we load this page into a browser, the details of all the courses are displayed. But let's say we want only the first 10. We can do that with limit iterator. So let's get back to the code. And the first thing that we need to do is to convert the simple XML element object into an iterator by adding the name of the simple XML iterator class as the second argument to simple XML load file. So let's add that second argument in there. It needs to be a string, SimpleXMLIterator. And this is case insensitive. Now that we've converted it into an iterator, we can chain it with the limit iterator. So let's add a new line on line three. We'll keep the same name, courses, and then it's new LimitInterator. The first argument is the iterator we want to limit.…
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)
-
-
-
-
-