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.
Extracting data from XML with RegexIterator and SimpleXML - PHP Tutorial
From the course: Learning the Standard PHP Library
Extracting data from XML with RegexIterator and SimpleXML
- This is courses.xml in the common data directory. It contains details of PHP courses in the lynda.com online training library. The root element is called courses, and then each individual top-level element is called course. And each course has a series of sub-elements such as title, author, description, level and so on. We can easily extract data from this file using SimpleXML and then filter it using RegexIterator. So let's create a new PHP file in the site root. We'll call it simplexml.php. We can load the XML using the SimpleXML load file function. So we'll call it courses, simplexml<u>load</u>file and it's the path common/data/courses.xml. This creates an instance of SimpleXML element and it contains all of the data from that file. And we can extract it using a foreach loop. So foreach courses as course and inside the loop, course represents one of the top-level elements in that XML document. I've given the variables the same names as the root elements and the top-level…
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)
-
-
-
-
-