From fe766c9622e119e106c71adbe697f6b0efec9275 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 28 Feb 2008 09:46:04 +0000 Subject: [PATCH] Utilities: added getDOMText helper function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@331 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/Utilities.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index a1aaf897f..b0a45d44a 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -595,6 +595,32 @@ class SimpleSAML_Utilities { return $ret; } + + /** + * This function extracts the text from DOMElements which should contain + * only text content. + * + * @param $element The element we should extract text from. + * @return The text content of the element. + */ + public static function getDOMText($element) { + assert('$element instanceof DOMElement'); + + $txt = ''; + + for($i = 0; $i < $element->childNodes->length; $i++) { + $child = $element->childNodes->item($i); + if(!($child instanceof DOMText)) { + throw new Exception($element->localName . ' contained a non-text child node.'); + } + + $txt .= $child->wholeText; + } + + $txt = trim($txt); + return $txt; + } + } ?> \ No newline at end of file -- GitLab