- preg_replace: documentation ( source)
<?php
$xml = <<<XML
<html>
<head><HEADER/></head>
<body>
<CONTENT/>
</body>
<FOOTER/>
</html>
XML;
$content = "<div id='main'>asdf asdf</div>";
$header = "<title>page 1</title>";
$footer = "<script type='text/javascript'></script>";
$xml = preg_replace('/<CONTENT\/>/',$content,$xml,1);
$xml = preg_replace('/<HEADER\/>/',$header,$xml,1);
$xml = preg_replace('/<FOOTER\/>/',$footer,$xml,1);
echo $xml;