我使用下面的代碼:PHP的DomDocument表現不同的CLI和Web瀏覽器
$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();
在CLI中運行它讓我
<!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>
,同時通過網頁瀏覽器中運行,它返回:
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>
現在我意識到嵌套內的(I)(p)標籤標記HTML破壞規則,但我不是一個負責日e HTML。出於某種原因,CLI模式會像原始文檔一樣返回文檔,而網頁版本會盡早關閉(i)標籤以保持HTML格式良好。
在我的php.ini配置中是否存在導致行爲差異的問題?我檢查了官方文檔(http://www.php.net/manual/en/dom.configuration.php),似乎沒有DomDocument的任何配置文件或設置。
這是奇數關閉strictErrorChecking,好運氣+1 – alex 2011-03-14 06:44:20
做你的'的phpinfo的 「DOM」 部分()'產生同樣的CLI和CGI的結果嗎? – 2011-03-14 07:12:27
^不,他們都顯示相同的設置。 – fsong 2011-03-14 08:26:48