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 contiene ningún parámetro.

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 ejemplo anterior mostrará :

# 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