Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HTML5.php

function HTML5::save

Save a DOM into a given file as HTML5.

Parameters

mixed $dom The DOM to be serialized.:

string|resource $file The filename to be written or resource to write to.:

array $options Configuration options when serializing the DOM. These include::

  • encode_entities: Text written to the output is escaped by default and not all

entities are encoded. If this is set to true all entities will be encoded. Defaults to false.

1 call to HTML5::save()
HTML5::saveHTML in vendor/masterminds/html5/src/HTML5.php
Convert a DOM into an HTML5 string.

File

vendor/masterminds/html5/src/HTML5.php, line 201

Class

HTML5
This class offers convenience methods for parsing and serializing HTML5. It is roughly designed to mirror the \DOMDocument native class.

Namespace

Masterminds

Code

public function save($dom, $file, $options = array()) {
    $close = true;
    if (is_resource($file)) {
        $stream = $file;
        $close = false;
    }
    else {
        $stream = fopen($file, 'wb');
    }
    $options = array_merge($this->defaultOptions, $options);
    $rules = new OutputRules($stream, $options);
    $trav = new Traverser($dom, $stream, $rules, $options);
    $trav->walk();
    
    /*
     * release the traverser to avoid cyclic references and allow PHP to free memory without waiting for gc_collect_cycles
     */
    $rules->unsetTraverser();
    if ($close) {
        fclose($stream);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal