filter_dom_serialize

Versions
7
filter_dom_serialize($dom_document)

Converts a DOM object back to an HTML snippet.

The function serializes the body part of a DOMDocument back to an XHTML snippet.

The resulting XHTML snippet will be properly formatted to be compatible with HTML user agents.

Parameters

$dom_document A DOMDocument object to serialize, only the tags below the first <body> node will be converted.

Return value

A valid (X)HTML snippet, as a string.

▾ 2 functions call filter_dom_serialize()

_filter_html in modules/filter/filter.module
HTML filter. Provides filtering of input into accepted HTML.
_filter_htmlcorrector in modules/filter/filter.module
Scan input and make sure that all HTML tags are properly closed and nested.

Code

modules/filter/filter.module, line 818

<?php
function filter_dom_serialize($dom_document) {
  $body_node = $dom_document->getElementsByTagName('body')->item(0);
  $body_content = '';
  foreach ($body_node->childNodes as $child_node) {
    $body_content .= $dom_document->saveXML($child_node);
  }
  return preg_replace('|<([^>]*)/>|i', '<$1 />', $body_content);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.