Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected end tag p in Entity in DOMDocument::loadHTML() error

Why do I get warning for this code?

$content ='<p>
 <a href="http://www.we.com/1000">text </a>
 text 
 <a href="http://www.we.com/2345">text </a>
  text 
</p>

<p>text</p>

<p>
  <table border="1" cellpadding="0" cellspacing="0" dir="rtl"> 
      <tbody> 
          <tr> 
              <td>text </td> 
              <td>text </td> 
              <td>text </td> 
          </tr> 
          <tr> 
              <td>text </td> 
              <td>text </td> 
              <td>text </td> 
          </tr> 
      </tbody> 
  </table>
</p>';

$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadHTML($content);

The warning is:

Warning: DOMDocument::loadHTML(): Unexpected end tag : p in Entity, line: 25 in /home/admin/domains/we.com/public_html/refresh/lib/core.php on line 2213 <p> <a href="http://www.we.com/1000">text </a> text <a href="http://www.we.com/2345">text </a> text </p> <p>text</p> <p> </p><table border="1" cellpadding="0" cellspacing="0" dir="rtl"><tbody><tr><td>text </td> <td>text </td> <td>text </td> </tr><tr><td>text </td> <td>text </td> <td>text </td> </tr></tbody></table>

like image 995
ali Avatar asked Dec 09 '22 04:12

ali


2 Answers

Add @ to suppress the warning as follows

@$doc->loadHTML($content);

This is because most of HTML objects are not perfectly formatted or even elements like "p" are automatically closed

like image 105
joash Avatar answered Dec 11 '22 10:12

joash


The end tag for paragraphs is optional. A table may not appear within a paragraph. The table start tag implicitly ends that paragraph. The next paragraph end tag has no open paragraph to close.

See "Tag omission in text/html" in the spec for p.

like image 21
Quentin Avatar answered Dec 11 '22 08:12

Quentin