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>
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With