I want to append my head tag with script tag(with some contents) in external Html file using PHP code.
But my Html is not updating or showing any errors.
PHP Code:
<?php
$doc = new DOMDocument();
$doc->loadHtmlFile( 'myfolder/myIndex.html');
$headNode = $doc->getElementsByTagName('head')->item(0);
$scriptNode = $doc->createElement("script");
$headNode->appendChild($scriptNode);
echo $doc->saveXML();
?>
Html File :
(A simple html pattern)
<html>
<head></head>
<body></body>
</html>
I have refered to the documentation here Couldn't figure out the problem still.
$doc->saveXML()would change the HTML file on the disk that you initially read the HTML code from …?