Thomas Meinike: Doctype Definition mit DOM erzeugen - wie?

Beitrag lesen

Hallo,

Fatal error: Call to undefined method DOMDocument::createDocumentType() in verzeichnis/forenbereichgenerator.php on line 35

Das neue Dokument hab ich übrigens so aufgerufen

$doc=new domDocument;

createDocumentType() ist auf DOMImplementation anzuwenden, z. B. so:

<?php

$imp=new DOMImplementation;
  $doctype=$imp->createDocumentType("HTML","-//W3C//DTD HTML 4.01 Transitional//EN","");
  $rootname="html";
  $namespace="";

$doc=$imp->createDocument($namespace,$rootname,$doctype);
  $root=$doc->documentElement;

$head=$doc->createElement("head");
  $body=$doc->createElement("body");
  $root->appendChild($head);
  $root->appendChild($body);

print "<pre>".htmlentities($doc->saveHTML())."</pre>";

?>

Ergebnis:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head></head>
<body></body>
</html>

MfG, Thomas