RegexIterator::accept

(PHP 5 >= 5.2.0, PHP 7)
Get accept status
public bool RegexIterator::accept ( void )

Matches (string) RegexIterator::current() (or RegexIterator::key() if the RegexIterator::USE_KEY flag is set) against the regular expression.

Returns:

TRUE if a match, FALSE otherwise.

Examples:
RegexIterator::accept() example

This example shows that only items matching the regular expression are accepted.

1
2
3
4
5
6
7
<?php
$names new ArrayIterator(array('Ann''Bob''Charlie''David'));
$filter new RegexIterator($names'/^[B-D]/');
foreach ($filter as $name) {
    echo $name . PHP_EOL;
}
?>

The above example will output:

Bob
Charlie
David
See also:

RegexIterator constants -

RegexIterator::setFlags() -

doc_php
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.