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

NETTUTS.com: Quick Tip: Loop Through Folders with PHP’s Glob()

NetTuts.com: Integrating Zendesk With WordPress

SitePoint PHP Blog: Yii 2.0 ActiveRecord Explained

PHPBuilder.com: MySQL and PHP: How to make it work without killing your server

GoodPHPTutorials.com: SQL Injections in PHP with MySQL


Community Events





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


security install series language tool introduction symfony podcast library interview version package update voicesoftheelephpant release opinion framework community laravel composer

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