使用PHP DOMDocument()类时保留换行符[复制]
发布时间:2020-12-13 22:26:50 所属栏目:PHP教程 来源:网络整理
导读:参见英文答案 PHP XML how to output nice format????????????????????????????????????7个 当您查看源代码时,我的HTML看起来像这样: 原始HTML !DOCTYPE htmlhtml head /head body /body/html 但在我这样做之后: $dom = new DOMDocument();$dom-loadHTML($
参见英文答案 >
PHP XML how to output nice format????????????????????????????????????7个
当您查看源代码时,我的HTML看起来像这样: 原始HTML <!DOCTYPE html> <html> <head> </head> <body> </body> </html> 但在我这样做之后: $dom = new DOMDocument(); $dom->loadHTML($html); $dom->saveHTML(); 我的源代码转向: 新的HTML <!DOCTYPE html><html><head></head><body></body></html> 使用PHP DOMDocument()类及其方法时,如何保留新行和空格? 解决方法
要保留空白,请尝试以下几行:
$dom=new DOMDocument('1.0','UTF-8'); $dom->formatOutput=false; $dom->preserveWhiteSpace=true; $dom->validateOnParse=false; $dom->standalone=true; $dom->strictErrorChecking=false; $dom->recover=true; 您可以设置一些其他属性 – 您可以在手册中找到它们 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |