DOM DOMDocument::getElementsByTagName
(PHP 5, PHP 7, PHP 8)
DOMDocument::getElementsByTagName — 주어진 로컬 태그 이름을 가진 모든 요소를 검색합니다.
설명
public DOMDocument::getElementsByTagName(string $qualifiedName
): DOMNodeList
이 함수는 주어진 로컬 태그 이름을 가진 모든 요소를 포함하는 DOMNodeList 클래스의 새 인스턴스를 반환합니다.
매개변수
qualifiedName
- 일치시킬 태그의 로컬 이름(네임스페이스 제외)입니다. 특수 값 *는 모든 태그와 일치합니다.
반환 값
일치하는 모든 요소를 포함하는 새 DOMNodeList 객체.
Examples
예제 #1 기본 사용 예
<?php
$xml = <<< XML
<?xml version="1.0" encoding="utf-8"?>
<books>
<book>Patterns of Enterprise Application Architecture</book>
<book>Design Patterns: Elements of Reusable Software Design</book>
<book>Clean Code</book>
</books>
XML;
$dom = new DOMDocument;
$dom->loadXML($xml);
$books = $dom->getElementsByTagName('book');
foreach ($books as $book) {
echo $book->nodeValue, PHP_EOL;
}
?>
위의 예는 다음을 출력합니다.
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code
기타
- DOMDocument::getElementsByTagNameNS() - 지정된 네임스페이스에서 지정된 태그 이름을 가진 모든 요소를 검색합니다.