PHP 8.1.28 Released!

tidyNode::isText

(PHP 5, PHP 7, PHP 8)

tidyNode::isTextComprueba si un nodo representa un texto (no HTML)

Descripción

public tidyNode::isText(): bool

Indica si un nodo representa sólo texto (sin nada de HTML).

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Devuelve true si un nodo representa un texto, false de lo contrario.

Ejemplos

Ejemplo #1 Extraer el texto de un documento HTML

<?php

$html
= <<< HTML
<html><head>
<?php echo '<title>titulo</title>'; ?>
<#
/* código JSTE */
alert('Hola Mundo');
#>
</head>
<body>

<?php
// código PHP
echo 'hola mundo!';
?>

<%
/* código ASP */
response.write("Hola Mundo!")
%>

<!-- Comentarios -->
Hola Mundo
</body></html>
Fuera del HTML
HTML;


$tidy = tidy_parse_string($html);
$num = 0;

get_nodes($tidy->html());

function
get_nodes($node) {

// Verifica si el nodo actual es del tipo requerido
if($node->isText()) {
echo
"\n\n# text node #" . ++$GLOBALS['num'] . "\n";
echo
$node->value;
}

// Verifica si el nodo actual tiene hijos
if($node->hasChildren()) {
foreach(
$node->child as $child) {
get_nodes($child);
}
}
}

?>

El resultado del ejemplo sería:

# text node #1
Hola Mundo

# text node #2
Fuera del HTML

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top