라이브러리

[PHP] DOMElement::removeAttributeNode - 속성 제거




DOMElement::removeAttributeNode


PHP의 DOMElement::removeAttributeNode 메소드는 DOMNode 객체를 인수로 받아서 해당 노드가 속한 요소의 특성을 제거합니다.

# 사용법


#hostingforum.kr
php

DOMNode removeAttributeNode(DOMNode $node)



* `$node` : 제거할 특성 노드

# 예제


#hostingforum.kr
php

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

$doc = new DOMDocument();



// HTML 문서를 생성합니다.

$html = '
테스트'; // HTML 문서를 DOMDocument 객체에 파싱합니다. $doc->loadHTML($html); // DOMElement 객체를 가져옵니다. $element = $doc->getElementById('test'); // 특성 노드를 생성합니다. $attribute = $doc->createAttribute('data-test'); $attribute->value = '테스트 값'; // 특성 노드를 요소에 추가합니다. $element->setAttributeNode($attribute); // 특성 노드를 제거합니다. $element->removeAttributeNode($attribute); // DOMDocument 객체의 HTML 문서를 출력합니다. echo $doc->saveHTML();


# 결과


#hostingforum.kr
html

테스트


# 참고


* DOMDocument 객체는 HTML 문서를 파싱하고, DOMElement 객체는 HTML 요소를 나타냅니다.
* DOMElement::removeAttributeNode 메소드는 특성 노드를 제거하여 요소의 특성을 제거합니다.
* 특성 노드를 제거한 후, DOMDocument 객체의 HTML 문서를 출력하면 제거된 특성이 제거된 것을 확인할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색