note 53026 modified in function.dom-domdocument-savexml by bjori

From: Date: Mon, 27 Mar 2006 00:27:01 +0000
Subject: note 53026 modified in function.dom-domdocument-savexml by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106693@lists.php.net to get a copy of this message
Say you want to put some XHTML inside an XML node and later extract it for output to the browser. For example: "<friend>Joanne <a href='joanne.com'>visit website</a></friend>" You need an innerXML function, similar to the Javascript innerHTML. It might look like this: function xt_innerXML(&$node){ if(!$node) return false; $document = $node->ownerDocument; $nodeAsString = $document->saveXML($node); preg_match('!\<.*?\>(.*)\</.*?\>!s',$nodeAsString,$match); return $match[1]; } --was-- A correction for the "innerXML" function I posted earlier: The only change is the "s" modifier at the end of the regular expression (i.e. 1st parameter for preg_match). That allows for newline characters in the "innerXML". Moderators, you may burn the other post. Thanks! Say you want to put some XHTML inside an XML node and later extract it for output to the browser. For example: "<friend>Joanne <a href='joanne.com'>visit website</a></friend>" You need an innerXML function, similar to the Javascript innerHTML. It might look like this: function xt_innerXML(&$node){ if(!$node) return false; $document = $node->ownerDocument; $nodeAsString = $document->saveXML($node); preg_match('!\<.*?\>(.*)\</.*?\>!s',$nodeAsString,$match); return $match[1]; } http://php.net/manual/en/function.dom-domdocument-savexml.php

« previous php.notes (#106693) next »