class="main"인
안의 class="text" 안의
태그 안의 텍스트는 다음 코드로 얻을 수 있습니다 -
예시
$html = <<<HTML
<div class="main">
<div class="text">
This is text 1
</div>
</div>
<div class="main">
<div class="text">
This is text 2
</div>
</div>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
XPath queries along with the DOMXPath::query method can be used to return the list of elements that are searched for by the user.
$tags = $xpath->query('//div[@class="main"]/div[@class="text"]');
foreach ($tags as $tag) {
var_dump(trim($tag->nodeValue));
} 출력
이것은 다음과 같은 출력을 생성합니다 -
string ‘This is text 1’ (length=14) string ‘This is text 2' (length=14)