표준 PHP 라이브러리(SPL) RegexIterator::setMode

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

RegexIterator::setMode — 작동 모드를 설정합니다.


설명

public RegexIterator::setMode(int $mode): void

작동 모드를 설정합니다.


매개변수

mode
작동 모드입니다.

사용 가능한 모드는 다음과 같습니다. 이러한 모드의 실제 의미는 predefined constants에 설명되어 있습니다.

RegexIterator modes


반환 값

값이 반환되지 않습니다.


Examples

예제 #1 RegexIterator::setMode() 예제

                  
<?php
$test = array ('str1' => 'test 1', 'test str2' => 'another test', 'str3' => 'test 123');

$arrayIterator = new ArrayIterator($test);
// Filter everything that starts with 'test ' followed by one or more numbers.
$regexIterator = new RegexIterator($arrayIterator, '/^test (\d+)/');
// Operation mode: Replace actual value with the matches
$regexIterator->setMode(RegexIterator::GET_MATCH);

foreach ($regexIterator as $key => $value) {
    // print out the matched number(s)
    echo $key . ' => ' . $value[1] . PHP_EOL;
}
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

str1 => 1
str3 => 123
                

기타