라이브러리

[PHP] DOMElement::hasAttribute - 속성이 존재하는지 확인합니다.




DOMElement::hasAttribute

DOMElement::hasAttribute 메소드는 DOMElement 객체가 특정 속성을 가지고 있는지 여부를 확인하는 메소드입니다. 이 메소드는 DOMElement 객체의 속성을 확인할 때 사용됩니다.

사용법


DOMElement::hasAttribute 메소드는 다음 형식으로 사용됩니다.

#hostingforum.kr
php

bool DOMElement::hasAttribute(string $name)



* `$name`: 확인할 속성 이름입니다.

예제


다음 예제는 DOMElement::hasAttribute 메소드를 사용하여 속성을 확인하는 방법을 보여줍니다.

#hostingforum.kr
php

<?php

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

$html = new DOMDocument();

$html->loadHTML('
Hello World!'); // DOMElement 객체를 생성합니다. $element = $html->getElementsByTagName('div')->item(0); // 속성을 확인합니다. echo var_export($element->hasAttribute('id'), true) . " "; // true echo var_export($element->hasAttribute('class'), true) . " "; // true echo var_export($element->hasAttribute('style'), true) . " "; // false


결과


#hostingforum.kr
php

true

true

false



참고


* DOMElement::hasAttribute 메소드는 속성이 존재하는지 여부를 boolean 값으로 반환합니다.
* 속성이 존재하지 않으면 false를 반환합니다.
* 속성이 존재하면 true를 반환합니다.

이 예제는 DOMElement::hasAttribute 메소드를 사용하여 속성을 확인하는 방법을 보여줍니다. 이 메소드는 DOMElement 객체의 속성을 확인할 때 사용됩니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색