PHPeste 2025 - Parnaiba-PI

Voting

: max(seven, nine)?
(Example: nine)

The Note You're Voting On

nawaman at gmail dot com
15 years ago
The following code shows can text-only content be extracted from a document.

<?php
function getTextFromNode($Node, $Text = "") {
if (
$Node->tagName == null)
return
$Text.$Node->textContent;

$Node = $Node->firstChild;
if (
$Node != null)
$Text = getTextFromNode($Node, $Text);

while(
$Node->nextSibling != null) {
$Text = getTextFromNode($Node->nextSibling, $Text);
$Node = $Node->nextSibling;
}
return
$Text;
}

function
getTextFromDocument($DOMDoc) {
return
getTextFromNode($DOMDoc->documentElement);
}

$Doc = new DOMDocument();
$Doc->loadHTMLFile("Test.html");
echo
getTextFromDocument($Doc)."\n";
?>

<< Back to user notes page

To Top