PHP Object-Oriented Solutions

Chapter 7

This chaper covers looping with the Standard PHP Library (SPL).

Exericses

Filtering a Loop with a Regular Expression
The first part just loads and loops through an XML file, while limiting the results. The second uses the same XML file, but only shows those titles and descriptions where "PHP" appears in the title.
Applying the Regular Expression to the Element Keys
The page displays various ways of using regualr expressions with the array being used shown to the right.
Using Anonymous Iterators as Shorthand Part 1 | Part 2
The page displays a script which calls limited information from two separate XML files. The second script uses a more succinct method of calling the XML files, combining them, and limiting the results.
Finding Files of a Particular Type
The page displays all the files with a .XML extension in the current directory.
Reading and Writing Files with SplFileObject
The page displays the contents of three .TXT files which are contained within a subfolder.
Understanding the Iterator Interface
The page displays the result of a script which uses all five methods of the iterator interface to iterate through an array and display the elements within.
Creating a Price Filter
The price filter is a class which extends FilterIterator. The page displays only those books which have a paperback version and are less than $40.00.