tidyNode::isHtml

(PHP 5, PHP 7, PHP 8)

tidyNode::isHtmlChecks if a node is an element node

Beschreibung

public tidyNode::isHtml(): bool

Tells if the node is an element node, but not the root node of the document.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Returns true if the node is an element node, but not the root node of the document, false otherwise.

Changelog

Version Beschreibung
7.3.24, 7.4.12 This function has been fixed to have reasonable behavior. Previously, almost any node was reported as being an HTML node.

Beispiele

Beispiel #1 Extract HTML code from a mixed HTML document

<?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);
        }
    }
}

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

# 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>

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Ferienhaus Buchungsmaschine

Ich würde das mit WordPress realisieren. Man kann dank AI auch den Content, Bilder und vieles mehr automatisiert erstellen lassen. Gibt schon ers ...

Geschrieben von Dirk25 am 11.07.2025 11:24:36
Forum: Jobgesuche
Berechnungen durchführen

Weg mit diesem SPAM!

Geschrieben von Dirk25 am 11.07.2025 11:21:51
Forum: PHP Developer Forum
Datenbank Manager

Hallo zusammen, ...weils so schön war gleich der nächste Beitrag... ich will mir einen sog. Datenbank MAnager programmieren, will heissen, ich ...

Geschrieben von tomatoyawl am 11.07.2025 06:38:27
Forum: SQL / Datenbanken
Berechnungen durchführen

it helps relax and reduce stress eggy car (https://eggycar2.io/)​

Geschrieben von fuitee am 11.07.2025 06:16:15
Forum: PHP Developer Forum