略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: RegexIterator::accept

2024-12-22

RegexIterator::accept

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

RegexIterator::acceptGet accept status

说明

public RegexIterator::accept(): bool

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

参数

此函数没有参数。

返回值

true if a match, false otherwise.

范例

示例 #1 RegexIterator::accept() example

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

<?php
$names 
= new ArrayIterator(array('Ann''Bob''Charlie''David'));
$filter = new RegexIterator($names'/^[B-D]/');
foreach (
$filter as $name) {
    echo 
$name PHP_EOL;
}
?>

以上例程会输出:

Bob
Charlie
David
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/regexiterator.accept.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3