php8.5
Home/ Manual/ spl / regexiterator/ RegexIterator::accept

RegexIterator::accept

PHP function Edit on GitHub ✎

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

Get accept status

Description

RegexIterator::accept(): bool

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

Parameters Parameters

Return Values

true if a match, false otherwise.

Examples

RegexIterator::accept example

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

php
<?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:

output
Bob
Charlie
David

See Also

Source: reference/spl/regexiterator/accept.xml · from the official PHP manual (php/doc-en)