라이브러리

[PHP] DOMDocumentFragment::append - 마지막 자식 노드 뒤에 노드를 추가합니다.




PHP DOMDocumentFragment::append


`DOMDocumentFragment`은 DOM 문서의 부분 문서를 나타내는 DOM 노드입니다. `append` 메소드는 DOM 노드를 문서의 끝에 추가하는 메소드입니다.

# 사용법


`append` 메소드는 다음 형식으로 사용할 수 있습니다.

#hostingforum.kr
php

DOMDocumentFragment::append($node)



* `$node` : 추가할 DOM 노드입니다.

# 예제


다음 예제는 `append` 메소드를 사용하여 DOM 노드를 문서의 끝에 추가하는 방법을 보여줍니다.

#hostingforum.kr
php

// DOMDocumentFragment 객체를 생성합니다.

$fragment = new DOMDocumentFragment();



// DOM 노드를 생성합니다.

$node1 = new DOMElement('div');

$node1->nodeValue = '노드 1';



$node2 = new DOMElement('span');

$node2->nodeValue = '노드 2';



// 노드를 문서의 끝에 추가합니다.

$fragment->appendChild($node1);

$fragment->appendChild($node2);



// DOMDocument 객체를 생성합니다.

$doc = new DOMDocument();



// 노드를 문서에 추가합니다.

$doc->appendChild($fragment);



// 문서를 출력합니다.

echo $doc->saveHTML();



이 예제에서는 `DOMDocumentFragment` 객체에 두 개의 노드를 추가하고, 그 노드를 `DOMDocument` 객체에 추가하여 문서를 출력합니다.

# 결과


#hostingforum.kr
html

노드 1노드 2



# 참고


`append` 메소드는 노드를 문서의 끝에 추가합니다. 만약 노드를 특정 위치에 추가하고 싶다면 `insertBefore` 메소드를 사용해야 합니다.

#hostingforum.kr
php

$fragment->insertBefore($node, $refNode);



* `$refNode` : 노드를 삽입할 위치의 노드입니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 615 페이지

검색

게시물 검색