Can create primary div without xml tags displaying and without any problem
$myfile = fopen("../userfolders/$email/$ongrassdb/$pagenameselected.php", "a+") or die("Unable to open file!");
$dom = new DOMDocument();
$ele = $dom->createElement('div', $textcon);
$ele ->setAttribute('id', $divname);
$ele ->setAttribute('style', 'background: '.$divbgcolor.'; color :'.$divfontcolor.' ;display : table-col; width :100%;');
$dom->appendChild($ele);
$html = $dom->saveHTML();
fwrite($myfile,$html);
fclose($myfile);
Trying to create child div but the below code creates duplicates of parent div and child div and adds XML tags after every div
$myfile = fopen("../userfolders/$email/$ongrassdb/$pagenameselected.php", "a+") or die("Unable to open file!");
$file = "../userfolders/$email/$ongrassdb/$pagenameselected.php";
$doc = new DOMDocument();
$doc->loadHTMLFile($file);
$ele = $doc->createElement('div', $textcon);
$element = $doc->getElementsByTagName('div')->item(0);
$element->appendChild($ele);
$ele ->setAttribute('id', $divname);
$ele ->setAttribute('style', 'background: '.$divbgcolor.'; color :'.$divfontcolor.' ;display : table-cell;');
$doc->appendChild($ele);
$html = $doc->saveHTML();
fwrite($myfile,$html);