PHP DomDocument behaves differently in CLI and web browser

I am using the following code:

$doc = new DOMDocument();
$doc->loadHTML("<i><p><strong>From: fsong | #001</strong><br/>I hate you DomDocument :(.</p></i><br/>you'd be surprised<br/>");
echo $doc->saveHTML();

Running it in the CLI bothers me

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<i><p><strong>From: fsong | #001</strong><br>I hate you DomDocument :(.</p></i><br>you'd be surprised<br>
</body></html>

when launched via a web browser returns:

Warning: DOMDocument::loadHTML(): Unexpected end tag : i in Entity, line: 1 in /home/xx/www/test/topic_archiver_test.php on line 50
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> 
<html><body> 
<i></i><p><strong>From: fsong | #001</strong><br>I hate you DomDocument :(.</p> 
<br>you'd be surprised<br> 
</body></html> 

Now I understand that the nested tag (p) inside the tag (i) violates the HTML rules, but I'm not the one responsible for HTML. For some reason, the CLI mode returns the document as the original, while the web page version closes the tag (i) early in order to preserve the correct HTML code.

Is there anything in my php.ini configurations that cause a difference in behavior? I checked the official docs ( http://www.php.net/manual/en/dom.configuration.php ) and there seems to be no configuration files or settings for DomDocument.

+3
source share
2 answers

, - HTML. php 5.3.5 libxml 2.7.6.

- "@", , .

@$dom->saveHTML();
+1

All Articles