라이브러리
[PHP] tidyNode::getParent - 현재 노드의 부모 노드를 반환합니다.
TidyNode::getParent() 메서드
TidyNode::getParent() 메서드는 TidyNode 객체의 부모 노드를 반환하는 메서드입니다. TidyNode 객체는 HTML 문서의 노드를 나타내며, 부모 노드는 해당 노드의 상위 노드를 의미합니다.
사용법
#hostingforum.kr
php
$tidy = new Tidy();
$html = '
Hello World!';
$tidy->parseString($html);
$root = $tidy->root();
$node = $root->child(0)->child(0);
// 부모 노드 가져오기
$parentNode = $node->getParent();
echo $parentNode->textContent; // "Hello World!"
예제
#hostingforum.kr
php
$html = '
제목
내용1
내용2
-
- 리스트1
- 리스트2
';
$tidy = new Tidy();
$tidy->parseString($html);
$root = $tidy->root();
// h1 노드 가져오기
$h1Node = $root->child(0)->child(0);
echo $h1Node->textContent; // "제목"
// p 노드 가져오기
$pNode = $h1Node->getParent()->child(1)->child(0);
echo $pNode->textContent; // "내용1"
// ul 노드 가져오기
$ulNode = $pNode->getParent()->child(3);
echo $ulNode->textContent; // "리스트1리스트2"
// li 노드 가져오기
$liNode = $ulNode->child(0);
echo $liNode->textContent; // "리스트1"
참고
* TidyNode::getParent() 메서드는 부모 노드를 반환하므로, 부모 노드가 없을 경우 NULL을 반환합니다.
* TidyNode 객체는 HTML 문서의 노드를 나타내므로, 부모 노드가 없을 경우 NULL을 반환합니다.
* TidyNode::getParent() 메서드는 TidyNode 객체의 부모 노드를 반환하므로, 부모 노드가 없을 경우 NULL을 반환합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.