News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Joshua Thijssen:
SPL Deepdive RegexIterator
February 13, 2014 @ 11:18:55

Joshua Thijssen has posted a deep dive with the RegexIterator to his site today. This iterator is part of the SPL (Standard PHP Library) that is included with PHP. It allows you to filter items based a given regular expression.

If everything goes according to plan (which never is the case), I'll try and highlight some of the fascinating stuff that can be found inside the SPL. I do a lot of presentations about the SPL, and one of the things I like to tell people is that even though the SPL, - iterators particularly - is a magnificent piece of code that is often underused and misunderstood, it does come with some quirks and glitches that aren't documented properly. Today, i'll explain a bit indepth the RegexIterator. This iterator extends the FilterIterator, meaning it can be used to filter out unwanted entries from parent iterators.

He gives a brief example of it in use to filter the results from a DirectoryIterator but quickly gets into the more advanced functionality. He looks at the different "modes" it can operate in: all matches, get matches, match, replace and split. He includes code examples and explanations for each of them, including the resulting output. He also shows how to filter based on the keys instead of values and briefly mentions the "preg_flags" but doesn't get too far into them as they change based on the mode being used.

0 comments voice your opinion now!
spl standardphplibrary regexiterator deepdive tutorial

Link: https://www.adayinthelifeof.nl/2014/02/12/spl-deepdive-regexiterator

blog comments powered by Disqus

Similar Posts

Jeremy Cook's Blog: Implementing the ArrayAccess Interface

Adam Pullen's Blog: Execution Filters in Symfony

The Bakery Blog: SwiftMailer Component Tutorial

ServerGrove Blog: Creating indexes for your Doctrine ODM documents with Symfony 2

Markus Wolff's Blog: Extending Zend_Controller_Action


Community Events





Don't see your event here?
Let us know!


install package release language laravel update introduction zendserver deployment api framework symfony podcast interview unittest community opinion tips series library

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework