在保存domdocument的同时删除doctype [英] removing doctype while saving domdocument
问题描述
我正在解析html文档并将其提取到DOMDocument。这些文档是子表单,将显示在另一个页面中。保存解析的DOMDocuments时,它会自动添加doctype,html,head和body标签。由于我正在处理子表单,因此我想删除所有这些表单并仅保存表单的子标签。
I am parsing and fetching html documents to DOMDocument. Those documents are child forms that will be displayed inside another page. While saving parsed DOMDocuments, it automatically adds doctype, html, head and body tags. since i am working on child forms i would like to remove all those and save only the child tags of form.
我如何跳过自动生成html,head,body的代码和其他标签同时保存domdocument?
How can i skip automatic generation of html, head, body and other tags while saving domdocument?
推荐答案
在阅读了数百个链接后,自己进行了设置。希望它也能帮助其他人...
Got it myself after reading through hundreds of links. hope it helps other guys too...
return preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $objDOM->saveHTML()));
详细信息:http://www.php.net/manual/en/domdocument.savehtml.php
这篇关于在保存domdocument的同时删除doctype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!