Is there a way to keep non standard DOM element ( in this case '<% .. %>' ) in the output ?
see my code below:
$html = '<html>';
$html .= '<body>';
$html .= '<% recipient.name %> ';
$html .='</body>';
$html .='</html>';
$document = new \DOMDocument('1.0');
$internalErrors = libxml_use_internal_errors(true);
$document->loadHTML($html);
libxml_use_internal_errors($internalErrors);
$out = $document->saveHTML();
print $out;
I am getting this output:
<html>
<head><meta content="text/html; http-equiv=" content-type></head>
<body> </body>
</html>
If the input is valid XML, you could wrap the template tags in <![CDATA[…]]>
and loadXML
will treat them as text nodes:
$html = '<html>';
$html .= '<body>';
$html .= '<![CDATA[<% recipient.name %>]]>';
$html .='</body>';
$html .='</html>';
$document = new \DOMDocument();
$document->loadXML($html);
print $document->saveHTML();
// <html><body><% recipient.name %></body></html>