Tidy tidyNode::isHtml
(PHP 5, PHP 7, PHP 8)
tidyNode::isHtml — 노드가 요소 노드인지 확인
설명
public tidyNode::isHtml(): bool
노드가 문서의 루트 노드가 아닌 요소 노드인지 여부를 알려줍니다.
매개변수
이 함수에는 매개변수가 없습니다.
반환 값
노드가 요소 노드이지만 문서의 루트 노드가 아니면 true
를 반환하고 그렇지 않으면 false
를 반환합니다.
변경 로그
버전 | 설명 |
---|---|
7.3.24, 7.4.12 | 이 함수는 합리적인 동작을 하도록 수정되었습니다. 이전에는 거의 모든 노드가 HTML 노드로 보고되었습니다. |
Examples
예제 #1 혼합 HTML 문서에서 HTML 코드 추출
<?php
$html = <<< HTML
<html><head>
<?php echo '<title>title</title>'; ?>
<#
/* JSTE code */
alert('Hello World');
#>
</head>
<body>
<?php
// PHP code
echo 'hello world!';
?>
<%
/* ASP code */
response.write("Hello World!")
%>
<!-- Comments -->
Hello World
</body></html>
Outside HTML
HTML;
$tidy = tidy_parse_string($html);
$num = 0;
get_nodes($tidy->html());
function get_nodes($node) {
// check if the current node is of requested type
if($node->isHtml()) {
echo "\n\n# html node #" . ++$GLOBALS['num'] . "\n";
echo $node->value;
}
// check if the current node has childrens
if($node->hasChildren()) {
foreach($node->child as $child) {
get_nodes($child);
}
}
}
?>
위의 예는 다음을 출력합니다.
# html node #1 <html> <head> <?php echo '<title>title</title>'; ?><# /* JSTE code */ alert('Hello World'); #> <title></title> </head> <body> <?php // PHP code echo 'hello world!'; ?><% /* ASP code */ response.write("Hello World!") %><!-- Comments --> Hello WorldOutside HTML </body> </html> # html node #2 <head> <?php echo '<title>title</title>'; ?><# /* JSTE code */ alert('Hello World'); #> <title></title> </head> # html node #3 <title></title> # html node #4 <body> <?php // PHP code echo 'hello world!'; ?><% /* ASP code */ response.write("Hello World!") %><!-- Comments --> Hello WorldOutside HTML </body>