RecursiveRegexIterator: : _ _construct
(PHP 5 >= 5.2.0, PHP 7)
RecursiveRegexIterator::__construct — Creates a new RecursiveRegexIterator
Description
$iterator
, string $regex
[, int $mode
= self::MATCH
[, int $flags
= 0
[, int $preg_flags
= 0
]]] )Creates a new regular expression iterator.
Parameters
-
iterator
-
The recursive iterator to apply this regex filter to.
-
regex
-
The regular expression to match.
-
mode
-
Operation mode, see RegexIterator::setMode() for a list of modes.
-
flags
-
Special flags, see RegexIterator::setFlags() for a list of available flags.
-
preg_flags
-
The regular expression flags. These flags depend on the operation mode parameter:
RegexIterator preg_flags operation mode available flags RecursiveRegexIterator::ALL_MATCHES See preg_match_all(). RecursiveRegexIterator::GET_MATCH See preg_match(). RecursiveRegexIterator::MATCH See preg_match(). RecursiveRegexIterator::REPLACE none. RecursiveRegexIterator::SPLIT See preg_split().
Examples
Example #1 RecursiveRegexIterator::__construct() example
Creates a new RegexIterator that filters all strings that start with 'test'.
<?php
$rArrayIterator = new RecursiveArrayIterator(array('test1', array('tet3', 'test4', 'test5')));
$rRegexIterator = new RecursiveRegexIterator($rArrayIterator, '/^test/',
RecursiveRegexIterator::ALL_MATCHES);
foreach ($rRegexIterator as $key1 => $value1) {
if ($rRegexIterator->hasChildren()) {
// print all children
echo "Children: ";
foreach ($rRegexIterator->getChildren() as $key => $value) {
echo $value . " ";
}
echo "\n";
} else {
echo "No children\n";
}
}
?>
The above example will output something similar to:
No children Children: test4 test5
See Also
- preg_match() - Perform a regular expression match
- preg_match_all() - Perform a global regular expression match
- preg_replace() - Perform a regular expression search and replace
- preg_split() - Split string by a regular expression
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-recursiveregexiterator.construct.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.