DOMDocument::saveHTML

(PHP 5, PHP 7)

DOMDocument::saveHTML Dumps the internal document into a string using HTML formatting

说明

public DOMDocument::saveHTML ([ DOMNode $node = NULL ] ) : string

Creates an HTML document from the DOM representation. This function is usually called after building a new dom document from scratch as in the example below.

参数

node

Optional parameter to output a subset of the document.

返回值

Returns the HTML, or FALSE if an error occurred.

更新日志

版本 说明
5.3.6 The node parameter was added.

范例

Example #1 Saving a HTML tree into a string

<?php

$doc 
= new DOMDocument('1.0');

$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 
$doc->saveHTML();

?>

参见

相关文章
php domdocument import node into current documentphp domdocument load html from a stringphp domdocument dumps the internal xml tree back into a filephp domdocument dumps the internal document into a string using html formattingphp domdocument dumps the internal document into a file using html formattingphp domdocument dumps the internal xml tree back into a stringphp domdocument validates a document based on a schemaphp variable handling 函数 dumps a string representation of an internal zend value to outputphp informix 函数 writes a string into the slob objectphp paradox 函数 converts a date into a stringphp simplexml 函数 interprets a string of xml into an objectphp xmlwriter 函数 create new xmlwriter using memory for string outputphp harudoc save the document into the specified filephp mysqlnduhconnection escapes special characters in a string for use in an sql statement taking into account the current charset of the connectionphp sdo das xml 函数 saves the sdo das xml document object to a stringphp solrquery returns the maximum number of characters into a document to look for suitable snippetsphp solrutils parses an response xml string into a solrobjectphp swfshape draws the first character in the given string into the shape using the glyph definition from the given fontphp swftext writes the given text into this swftext object at the current pen position using the current font height spacing and colorphp tidy indicates if the document is a generic non html/xhtml xml document
关注编程学问公众号