class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator (View source)

This recursive iterator can filter another recursive iterator via a regular expression.

Constants

ALL_MATCHES

Return all matches for the current entry preg_match_all

GET_MATCH

Return the first match for the current entry preg_match

MATCH

Only execute match (filter) for the current entry preg_match

REPLACE

Replace the current entry (Not fully implemented yet) preg_replace

SPLIT

Returns the split values for the current entry preg_split

USE_KEY

Special flag: Match the entry key instead of the entry value.

INVERT_MATCH

Properties

$replacement from  RegexIterator

Methods

__construct(Traversable $iterator, string $pattern, int $mode = RegexIterator::MATCH, int $flags = 0, int $pregFlags = 0)

Creates a new RecursiveRegexIterator.

Iterator|null
getInnerIterator()

Get the inner iterator

void
rewind()

Rewind the iterator

bool
valid()

Check whether the current element is valid

mixed
key()

Get the current key

mixed
current()

Get the current element value

void
next()

Move the iterator forward

bool
accept()

Get accept status

int
getMode()

Returns operation mode.

void
setMode(int $mode)

Sets the operation mode.

int
getFlags()

Get flags

void
setFlags(int $flags)

Sets the flags.

string
getRegex()

Returns current regular expression

int
getPregFlags()

Returns the regular expression flags.

void
setPregFlags(int $pregFlags)

Sets the regular expression flags.

bool
hasChildren()

Returns whether an iterator can be obtained for the current entry.

getChildren()

Returns an iterator for the current entry.

Details

__construct(Traversable $iterator, string $pattern, int $mode = RegexIterator::MATCH, int $flags = 0, int $pregFlags = 0)

Creates a new RecursiveRegexIterator.

Parameters

Traversable $iterator
string $pattern

The regular expression to match.

int $mode

[optional] Operation mode, see RegexIterator::setMode() for a list of modes.

int $flags

[optional] Special flags, see RegexIterator::setFlags() for a list of available flags.

int $pregFlags

[optional] The regular expression flags. These flags depend on the operation mode parameter

Iterator|null getInnerIterator()

Get the inner iterator

Return Value

Iterator|null

The inner iterator for the current entry.

void rewind()

Rewind the iterator

Return Value

void

Any returned value is ignored.

bool valid()

Check whether the current element is valid

Return Value

bool

The return value will be casted to boolean and then evaluated. Returns true on success or false on failure.

mixed key()

Get the current key

Return Value

mixed

TKey on success, or null on failure.

mixed current()

Get the current element value

Return Value

mixed

Can return any type.

void next()

Move the iterator forward

Return Value

void

Any returned value is ignored.

bool accept()

Get accept status

Return Value

bool

true if the current element is acceptable, otherwise false.

int getMode()

Returns operation mode.

Return Value

int

the operation mode.

void setMode(int $mode)

Sets the operation mode.

Parameters

int $mode

The operation mode.

The available modes are listed below. The actual meanings of these modes are described in the predefined constants.

RegexIterator modes
value constant
0 RegexIterator::MATCH
1 RegexIterator::GET_MATCH
2 RegexIterator::ALL_MATCHES
3 RegexIterator::SPLIT
4 RegexIterator::REPLACE

Return Value

void

int getFlags()

Get flags

Return Value

int

the set flags.

void setFlags(int $flags)

Sets the flags.

Parameters

int $flags

The flags to set, a bitmask of class constants.

The available flags are listed below. The actual meanings of these flags are described in the predefined constants.

RegexIterator flags
value constant
1 RegexIterator::USE_KEY

Return Value

void

string getRegex()

Since: 5.4

Returns current regular expression

Return Value

string

int getPregFlags()

Returns the regular expression flags.

Return Value

int

a bitmask of the regular expression flags.

void setPregFlags(int $pregFlags)

Sets the regular expression flags.

Parameters

int $pregFlags

The regular expression flags. See RegexIterator::__construct for an overview of available flags.

Return Value

void

bool hasChildren()

Returns whether an iterator can be obtained for the current entry.

Return Value

bool

true if the current entry can be iterated over, otherwise returns false.

RecursiveIterator|null getChildren()

Returns an iterator for the current entry.

Return Value

RecursiveIterator|null

An iterator for the current entry.