Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

DOMDocument->saveHTMLFile()

(no version information, might be only in CVS)

DOMDocument->saveHTMLFile() --  Dumps the internal document into a file using HTML formatting

Описание

class DOMDocument {

int saveHTMLFile ( string filename )

}

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.

Список параметров

filename

The path to the saved HTML document.

Возвращаемые значения

Returns the number of bytes written or FALSE if an error occurred.

Примеры

Пример 1. Saving a HTML tree into a file

<?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

?>



add a note add a note User Contributed Notes
DOMDocument->saveHTMLFile()
dev at asp55-ns dot com
13-Sep-2007 04:26
So one thing I've noticed is that DOMDocument->saveHTMLFile() does not create W3C valid HTML. <br> and <img> nodes aren't closed, leading to errors if you want to validate it.

To fix this, I've created a simple function.

<?php
function valid_saveHTMLFile($in,$outputFile) {
       
$in = preg_replace('/<br(.*?)\/?>/','<br$1/>',$in);
       
$in = preg_replace('/<img(.*?)\/?>/','<img$1/>',$in);
        return
file_put_contents($outputFile,$in);
}
?>

to call it

<?php
valid_saveHTMLFile
($dom->saveHTML(),'pathtofile');
?>

with $dom being your DOMDocument, and 'pathtofile' being...here's a surprise...the path to your save file.

The function returns the exact same thing file_put_contents returns (ie: The function returns the amount of bytes that were written to the file, or FALSE on failure.)

DOMDocument->saveXML()> <DOMDocument->saveHTML()
Last updated: Sat, 27 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571