Tidy tidyNode::isText

(PHP 5, PHP 7, PHP 8)

tidyNode::isText — 노드가 텍스트를 나타내는지 확인(마크업 없음)


설명

public tidyNode::isText(): bool

노드가 마크업 없이 텍스트를 나타내는지 여부를 알려줍니다.


매개변수

이 함수에는 매개변수가 없습니다.


반환 값

노드가 텍스트를 나타내면 true를 반환하고 그렇지 않으면 false를 반환합니다.


Examples

예제 #1 혼합 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->isText()) {
        echo "\n\n# text 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);
        }
    }
}

?>
                  
                

위의 예는 다음을 출력합니다.

# text node #1
Hello World

# text node #2
Outside HTML