I am using the below code to create a div <-- successfully. The problem is when i try to create a child div and select $pagenameselected.php to load. Here I get an error because when it loads $pagenameselected <-- it load the php script to create the div and not the created div like i can see in page source.
<?php
$myfile = fopen("../userfolders/$email/$ongrassdb/$pagenameselected.php", "w") or die("Unable to open file!");
$x = "<?php " . '$dom' . "= new DOMDocument();" .
'$element' . "= " . '$dom' . "->createElement('div', '$textcon');" .
'$dom' . "->appendChild(" . '$element' . ");
echo " . '$dom' . "->saveXML();?>";
fwrite($myfile,$x);
fclose($myfile);
?>
$myfile = fopen("../userfolders/$email/$ongrassdb/$pagenameselected.php", "w") or die("Unable to open file!");
$file = $DOCUMENT_ROOT. "../userfolders/$email/$ongrassdb/$pagenameselected.php";
$doc = new DOMDocument();
$doc->loadHTMLFile($file);
//$elements = $doc->getElementsByTagName('div');