php DOMImplementation自闭标签

时间:2014-10-31 07:09:00

标签: php html dom tags

我需要使用php DOMImplementation创建自我关闭标签,但我不知道如何。 我有这种代码和平

$doc = new DOMImplementation();
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;


//create and set doctype for html5
$doctype = $doc->createDocumentType('html', '', '');
$doc = $doc->createDocument("", "", $doctype);

//here elements are created
$html = $doc->createElement("html");
$head = $doc->createElement("head");
$body = $doc->createElement("body");

$css = $doc->createElement("link",'');
$css->setAttribute("rel", "stylesheet");
$css->setAttribute("href", "code.css");
$css->setAttribute("type", "text/css");

$head->appendChild( $css );

$html->appendChild( $head );

$html->appendChild( $body );

$doc->appendChild( $html );
$xml_string = $doc->saveHTML() ;
echo $xml_string;

但是当我创建链接元素时,我得到了

<link rel="stylesheet" href="code.css" type="text/css"></link>

我将如何获得

<link rel="stylesheet" href="code.css" type="text/css">

0 个答案:

没有答案