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

Breadcrumb

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

function HTML5::parseFragment

Parse an input stream where the stream is a fragment.

Lower-level loading function. This requires an input stream instead of a string, file, or resource.

Parameters

string $input The input data to parse in the form of a string.:

array $options An array of options.:

Return value

\DOMDocumentFragment

1 call to HTML5::parseFragment()
HTML5::loadHTMLFragment in vendor/masterminds/html5/src/HTML5.php
Parse a HTML fragment from a string.

File

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

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 parseFragment($input, array $options = array()) {
    $options = array_merge($this->defaultOptions, $options);
    $events = new DOMTreeBuilder(true, $options);
    $scanner = new Scanner($input, !empty($options['encoding']) ? $options['encoding'] : 'UTF-8');
    $parser = new Tokenizer($scanner, $events, !empty($options['xmlNamespaces']) ? Tokenizer::CONFORMANT_XML : Tokenizer::CONFORMANT_HTML);
    $parser->parse();
    $this->errors = $events->getErrors();
    return $events->fragment();
}

API Navigation

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