DOMDocument::save
(PHP 5, PHP 7)
DOMDocument :: save - 将内部XML树转储回文件
描述
public int DOMDocument::save ( string $filename [, int $options ] )
从DOM表示中创建一个XML文档。这个函数通常在从头开始构建一个新的dom文档后调用,如下例所示。
参数
filename
保存的XML文档的路径。
options
其他选项。目前只支持LIBXML_NOEMPTYTAG。
返回值
返回写入的字节数或FALSE
发生错误的次数。
更新日志
版 | 描述 |
---|---|
5.1.0 | 添加了选项参数 |
例子
Example#1将DOM树保存到文件中
<?php
$doc?=?new?DOMDocument('1.0');
//?we?want?a?nice?output
$doc->formatOutput?=?true;
$root?=?$doc->createElement('book');
$root?=?$doc->appendChild($root);
$title?=?$doc->createElement('title');
$title?=?$root->appendChild($title);
$text?=?$doc->createTextNode('This?is?the?title');
$text?=?$title->appendChild($text);
echo?'Wrote:?'?.?$doc->save("/tmp/test.xml")?.?'?bytes';?//?Wrote:?72?bytes
?>
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com