Estoy trabajando en un motor de plantillas pequeño, y estoy usando DOMDocument para analizar las páginas. Mi página de prueba hasta ahora se ve así:DOMDocument PHP pegando etiquetas HTML
<block name="content">
<?php echo 'this is some rendered PHP! <br />' ?>
<p>Main column of <span>content</span></p>
</block>
Y parte de mi clase tiene este aspecto:
private function parse($tag, $attr = 'name')
{
$strict = 0;
/*** the array to return ***/
$out = array();
if($this->totalBlocks() > 0)
{
/*** a new dom object ***/
$dom = new domDocument;
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** load the html into the object ***/
if($strict==1)
{
$dom->loadXML($this->file_contents);
}
else
{
$dom->loadHTML($this->file_contents);
}
/*** the tag by its tag name ***/
$content = $dom->getElementsByTagname($tag);
$i = 0;
foreach ($content as $item)
{
/*** add node value to the out array ***/
$out[$i]['name'] = $item->getAttribute($attr);
$out[$i]['value'] = $item->nodeValue;
$i++;
}
}
return $out;
}
he que funcione de la manera que quiero en la que se agarra cada <bloque> en el página e inyecta sus contenidos en mi plantilla, sin embargo, está eliminando las etiquetas HTML dentro del bloque < >, devolviendo así lo siguiente sin el <p> o <span> etiquetas:
this is some rendered PHP! Main column of content
¿Qué estoy haciendo mal aquí? :) Gracias