라이브러리
[PHP] RegexIterator::__construct - 새로운 RegexIterator 생성
RegexIterator::__construct
PHP의 `RegexIterator` 클래스는 `Iterator` 인터페이스를 구현한 클래스로, 정규표현식에 일치하는 요소를 반복적으로 반환합니다. `RegexIterator::__construct` 메서드는 `RegexIterator` 객체를 생성하는 데 사용됩니다.
# 생성자 메서드
`RegexIterator::__construct` 메서드는 다음과 같은 매개변수를 가집니다.
* `string $pattern`: 정규표현식 패턴
* `array $array`: 검색할 배열
* `int $flags`: 정규표현식 플래그
* `int $mode`: 검색 모드
# 매개변수 설명
* `string $pattern`: 정규표현식 패턴을 지정합니다. 예를 들어, `'/^hello/'`는 문자열이 'hello'로 시작하는지 확인합니다.
* `array $array`: 검색할 배열을 지정합니다. 예를 들어, `array('hello', 'world', 'hello world')`는 'hello'와 'world'를 포함하는 배열입니다.
* `int $flags`: 정규표현식 플래그를 지정합니다. 예를 들어, `PREG_CASELESS`는 대소문자를 구별하지 않습니다.
* `int $mode`: 검색 모드를 지정합니다. 예를 들어, `RegexIterator::GET_MATCH`는 일치하는 문자열을 반환합니다.
# 예제
#hostingforum.kr
php
// 예제 1: 'hello'로 시작하는 요소를 검색
$array = array('hello', 'world', 'hello world');
$regexIterator = new RegexIterator($array, '/^hello/');
foreach ($regexIterator as $item) {
echo $item . "
";
}
// 예제 2: 'hello'와 'world'를 포함하는 요소를 검색
$array = array('hello', 'world', 'hello world');
$regexIterator = new RegexIterator($array, '/hello|world/');
foreach ($regexIterator as $item) {
echo $item . "
";
}
// 예제 3: 대소문자를 구별하지 않고 'hello'로 시작하는 요소를 검색
$array = array('hello', 'world', 'HELLO world');
$regexIterator = new RegexIterator($array, '/^hello/', PREG_CASELESS);
foreach ($regexIterator as $item) {
echo $item . "
";
}
# 참고
* `RegexIterator` 클래스는 `Iterator` 인터페이스를 구현한 클래스로, 정규표현식에 일치하는 요소를 반복적으로 반환합니다.
* `RegexIterator::__construct` 메서드는 `RegexIterator` 객체를 생성하는 데 사용됩니다.
* 정규표현식 패턴은 `string` 타입의 매개변수로 전달됩니다.
* 검색할 배열은 `array` 타입의 매개변수로 전달됩니다.
* 정규표현식 플래그는 `int` 타입의 매개변수로 전달됩니다.
* 검색 모드는 `int` 타입의 매개변수로 전달됩니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.