Hey,
I would like to embed a custom header and footer. I would go about retrieving the data like this and putting it into a html file for caching.
Is there an easy way to include the output file as header/footer, so it is dynamically updated?
I would like to embed a custom header and footer. I would go about retrieving the data like this and putting it into a html file for caching.
PHP:
$data = file_get_contents('http://site-with-header.com');
$doc = new DOMDocument();
$doc->loadHTML($data);
$xpath = new DOMXpath($doc);
$head = $xpath->query("//head");
$header = $xpath->query("//header");
$footer = $xpath->query("//footer");
function domNodeList_to_string($DomNodeList) {
$output = '';
$doc = new DOMDocument;
while ( $node = $DomNodeList->item($i) ) {
$domNode = $doc->importNode($node, true);
$doc->appendChild($domNode);
$i++;
}
$output = $doc->saveHTML();
$output = print_r($output, 1);
return $output;
}
echo domNodeList_to_string($head);
echo "<style type='text/css'> html {max-width: 960px; margin: auto;} </style>";
echo domNodeList_to_string($header);
// Content
echo domNodeList_to_string($footer);
?>
Is there an easy way to include the output file as header/footer, so it is dynamically updated?