You are here

protected function Atom::_loadXhtml in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Atom.php \Zend\Feed\Writer\Renderer\Entry\Atom::_loadXhtml()

Load a HTML string and attempt to normalise to XML

1 call to Atom::_loadXhtml()
Atom::_setContent in vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Atom.php
Set entry content

File

vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Atom.php, line 359

Class

Atom

Namespace

Zend\Feed\Writer\Renderer\Entry

Code

protected function _loadXhtml($content) {
  if (class_exists('tidy', false)) {
    $tidy = new \tidy();
    $config = [
      'output-xhtml' => true,
      'show-body-only' => true,
      'quote-nbsp' => false,
    ];
    $encoding = str_replace('-', '', $this
      ->getEncoding());
    $tidy
      ->parseString($content, $config, $encoding);
    $tidy
      ->cleanRepair();
    $xhtml = (string) $tidy;
  }
  else {
    $xhtml = $content;
  }
  $xhtml = preg_replace([
    "/(<[\\/]?)([a-zA-Z]+)/",
  ], '$1xhtml:$2', $xhtml);
  $dom = new DOMDocument('1.0', $this
    ->getEncoding());
  $dom
    ->loadXML('<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">' . $xhtml . '</xhtml:div>');
  return $dom->documentElement;
}