略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: RegexIterator::setPregFlags

2024-12-21

RegexIterator::setPregFlags

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

RegexIterator::setPregFlagsSets the regular expression flags

说明

public RegexIterator::setPregFlags(int $pregFlags): void

Sets the regular expression flags.

参数

pregFlags

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

返回值

没有返回值。

范例

示例 #1 RegexIterator::setPregFlags() example

Creates a new RegexIterator that filters all entries with where the array key starts with 'test'.

<?php
$test 
= array ('test 1''another test''test 123');

$arrayIterator = new ArrayIterator($test);
$regexIterator = new RegexIterator($arrayIterator'/^test/'RegexIterator::GET_MATCH);

$regexIterator->setPregFlags(PREG_OFFSET_CAPTURE);

foreach (
$regexIterator as $key => $value) {
    
var_dump($value);
}
?>

以上例程的输出类似于:

array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(4) "test"
    [1]=>
    int(0)
  }
}
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(4) "test"
    [1]=>
    int(0)
  }
}

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

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

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