To add on to the other example, here's how to create an XHTML 1.0 transitional document with head, title, and body elements.
<?php
$document = DOMImplementation::createDocument(null, 'html',
DOMImplementation::createDocumentType("html",
"-//W3C//DTD XHTML 1.0 Transitional//EN",
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"));
$document->formatOutput = true;
$html = $document->documentElement;
$head = $document->createElement('head');
$title = $document->createElement('title');
$text = $document->createTextNode('Title of Page');
$body = $document->createElement('body');
$title->appendChild($text);
$head->appendChild($title);
$html->appendChild($head);
$html->appendChild($body);
echo $document->saveXML();
?>
This outputs: (http links removed due to spam)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "doctype.dtd">
<html xmlns="w3org1999xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title of Page</title>
</head>
<body></body>
</html>
Note the saveXML function. If saveHTML was used instead, you get the output:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "doctype.dtd">
<html>
<head><title>Title of Page</title></head>
<body></body>
</html>
DOMImplementation::createDocument
(PHP 5)
DOMImplementation::createDocument — Belge elemanı belirtilen DOMDocument nesnesini oluşturur
Açıklama
$uri = NULL
[, string $önekliAd = NULL
[, DOMDocumentType $belgeTürü = NULL
]]] )Belge elemanı belirtilen DOMDocument nesnesini oluşturur.
Değiştirgeler
-
uri -
Oluşturulacak belge elemanının isim alanını betimleyen adres.
-
önekliAd -
Oluşturulacak belge elemanının isim alanı önekli ismi.
-
belgeTürü -
Oluşturulacak belgenin türü veya
NULL.
Dönen Değerler
Yeni bir DOMDocument nesnesi.
uri, önekliAd ve
belgeTürü olarak NULL belirtilirse belge elemanı
olmayan boş bir DOMDocument nesnesi döner.
Hatalar/İstisnalar
-
DOM_WRONG_DOCUMENT_ERR -
belgeTürübaşka bir belgede zaten kullanılmışsa veya başka bir gerçeklenim tarafından oluşturulmuşsa bu hata oluşur. -
DOM_NAMESPACE_ERR -
uriveönekliAdile saptanan isim alanı ile ilgili bir hata durumunda bu hata oluşur.
Ayrıca Bakınız
- DOMDocument::__construct() - Yeni bir DOMDocument nesnesi oluşturur
- DOMImplementation::createDocumentType() - Boş bir DOMDocumentType nesnesi oluşturur
To create HTML document with doctype:
<?php
$doctype = DOMImplementation::createDocumentType("html",
"-//W3C//DTD HTML 4.01//EN",
"http://www.w3.org/TR/html4/strict.dtd");
$doc = DOMImplementation::createDocument(null, 'html', $doctype);
?>
