Skip to content

Warning: DOMDocument::loadHTML(): Unexpected end tag : u in Entity #118

Open
@tkoop

Description

@tkoop

We sometimes get this "Unexpected end tag" problem, and this is how to reproduce it. The following PHP file is very sensitive to spaces, so make sure each and every space is copied correct.y The above warning seems to go away when we use the "keep new lines" config option and remove all the spaces.

<html>

<p>This code fails.  To get it working, remove one space before the "ol" tag on line 31, which is just under "...Something here..." in $newHtml</p>

<?php

$oldHtml = '<ol>
        <li><u>Publication:</u>
          <ol>
            <li>This sentence.</li>
          </ol>
        </li>
        <li><u>Something here</u>:
          <ol>
            <li>Another item</li>
          </ol>
        </li>
      </ol>
      <ol>
        <li><u>Mars</u>:</li>
        <li>Saturn</li>
      </ol>';

      $newHtml = '<ol>
    <li><u>Publication:</u>
     <ol>
     <li>This sentence.</li>
     </ol>
     </li>
     <li><u>Something here</u>:
      <ol>
      <li>Another item</li>
      </ol>
      </li>
      <li><u>Mars</u>:
      <ol>
      <li>Saturn</li>
      </ol>
      </li>
    </ol>';

error_reporting(E_ALL);
ini_set('display_errors', '1');

require __DIR__ . '/../vendor/autoload.php';

use Caxy\HtmlDiff\HtmlDiff;
use Caxy\HtmlDiff\HtmlDiffConfig;

$config = new HtmlDiffConfig();
$config->setKeepNewLines(true);

$htmlDiff = HtmlDiff::create($oldHtml, $newHtml, $config);
$content = $htmlDiff->build();

echo "Diff is " . $content;

?>

</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions