首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

DOMDocument::saveHTMLFile

(PHP 5, PHP 7)

DOMDocument :: saveHTMLFile - 使用HTML格式将内部文档转储为文件

描述

代码语言:javascript
复制
public int DOMDocument::saveHTMLFile ( string $filename )

从DOM表示中创建一个HTML文档。这个函数通常在从头开始构建一个新的dom文档后调用,如下例所示。

参数

filename

保存的HTML文档的路径。

返回值

返回写入的字节数或FALSE发生错误的次数。

例子

示例#1将HTML树保存到文件中

代码语言:javascript
复制
<?php

$doc?=?new?DOMDocument('1.0');
//?we?want?a?nice?output
$doc->formatOutput?=?true;

$root?=?$doc->createElement('html');
$root?=?$doc->appendChild($root);

$head?=?$doc->createElement('head');
$head?=?$root->appendChild($head);

$title?=?$doc->createElement('title');
$title?=?$head->appendChild($title);

$text?=?$doc->createTextNode('This?is?the?title');
$text?=?$title->appendChild($text);

echo?'Wrote:?'?.?$doc->saveHTMLFile("/tmp/test.html")?.?'?bytes';?//?Wrote:?129?bytes

?>

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com