Hey everybody,
The following has been posted before (2 years ago) but no response was
added. Therefor again, the following code for creating xhtml file:
<?php
error_reporting (6143);
$xmlns = "http://www.w3.org/1999/xhtml";
$lang = "en";
$xhtml_1_strict = new DomImplementati on();
$dtd_xhtml_1_st rict = $xhtml_1_strict->createDocument Type("html", "-//
W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-strict.dtd");
$xhtml_1_strict _document = $xhtml_1_strict->createDocument ("", "",
$dtd_xhtml_1_st rict);
$xhtml_1_strict _document->encoding = "UTF-8";
$xhtml_1_strict _document->standalone = "no";
$html = $xhtml_1_strict _document->createElementN S($xmlns, "html");
$html->setAttribute(" xml:lang", $lang);
$head = $xhtml_1_strict _document->createElement( "head");
$html->appendChild($h ead);
$title = $xhtml_1_strict _document->createElement( "title", "Testing the
DOM in PHP5");
$head->appendChild($t itle);
$base = $xhtml_1_strict _document->createElement( "base");
$base->setAttribute(" href", "http://test.beatter.co m");
$head->appendChild($b ase);
$meta = $xhtml_1_strict _document->createElement( "meta");
$meta->setAttribute(" http-equiv", "Content-Type");
$meta->setAttribute(" content", "applicatio n/xhtml+xml;UTF-8");
$head->appendChild($m eta);
$body = $xhtml_1_strict _document->createElement( "body");
$html->appendChild($b ody);
$xhtml_1_strict _document->appendChild($h tml);
header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_s trict_document->saveXML());
?>
the expected output would be:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
<meta http-equiv="Content-Type" content="applic ation/xhtml
+xml;UTF-8" />
</head>
<body>
</body>
</html>
but the output is:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<title>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
</head>
<body>
</body>
</html>
Why does php add this node by itself? Why can't I override that
behavior? Why does php change the order of outputing the elements (I'm
appending, not pre-pending to the head element)?
Thanks,
Marijn
The following has been posted before (2 years ago) but no response was
added. Therefor again, the following code for creating xhtml file:
<?php
error_reporting (6143);
$xmlns = "http://www.w3.org/1999/xhtml";
$lang = "en";
$xhtml_1_strict = new DomImplementati on();
$dtd_xhtml_1_st rict = $xhtml_1_strict->createDocument Type("html", "-//
W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-strict.dtd");
$xhtml_1_strict _document = $xhtml_1_strict->createDocument ("", "",
$dtd_xhtml_1_st rict);
$xhtml_1_strict _document->encoding = "UTF-8";
$xhtml_1_strict _document->standalone = "no";
$html = $xhtml_1_strict _document->createElementN S($xmlns, "html");
$html->setAttribute(" xml:lang", $lang);
$head = $xhtml_1_strict _document->createElement( "head");
$html->appendChild($h ead);
$title = $xhtml_1_strict _document->createElement( "title", "Testing the
DOM in PHP5");
$head->appendChild($t itle);
$base = $xhtml_1_strict _document->createElement( "base");
$base->setAttribute(" href", "http://test.beatter.co m");
$head->appendChild($b ase);
$meta = $xhtml_1_strict _document->createElement( "meta");
$meta->setAttribute(" http-equiv", "Content-Type");
$meta->setAttribute(" content", "applicatio n/xhtml+xml;UTF-8");
$head->appendChild($m eta);
$body = $xhtml_1_strict _document->createElement( "body");
$html->appendChild($b ody);
$xhtml_1_strict _document->appendChild($h tml);
header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_s trict_document->saveXML());
?>
the expected output would be:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
<meta http-equiv="Content-Type" content="applic ation/xhtml
+xml;UTF-8" />
</head>
<body>
</body>
</html>
but the output is:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<title>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
</head>
<body>
</body>
</html>
Why does php add this node by itself? Why can't I override that
behavior? Why does php change the order of outputing the elements (I'm
appending, not pre-pending to the head element)?
Thanks,
Marijn
Comment