Jump to content

Php Create Element


driz

Recommended Posts

Can the following be done using PHP:

function createHTML5Elements() {	document.createElement("article");	document.createElement("nav");	document.createElement("section");	document.createElement("header");	document.createElement("hgroup");	document.createElement("aside");	document.createElement("footer");}createHTML5Elements();

Link to comment
Share on other sites

Not exactly. It can be applied on a previously opened DOMDocument, but it doesn't apply on the final document, as is in JavaScript. This is because PHP outputs "text" (in any form) whereas JavaScript uses DOM to manipulate the current page.Assuming you have a global variable that is an opened document, you can have:

$document = new DOMDocument; //In order to create a new empty DOM document.function createHTML5Elements() {	global $document; //In order to let the function use the global variable.	$document->createElement("article");	$document->createElement("nav");	$document->createElement("section");	$document->createElement("header");	$document->createElement("hgroup");	$document->createElement("aside");	$document->createElement("footer");}createHTML5Elements();//Do other DOM manipulations here... like actually inserting the elements for example.echo $document->saveXML(); //In order to actually output the contents.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...