Je travaille sur un petit moteur de template, et j'utilise DOMDocument pour analyser les pages. Ma page de test afin ressemble beaucoup à ceci:PHP DOMDocument dépouillant les balises HTML
<block name="content">
<?php echo 'this is some rendered PHP! <br />' ?>
<p>Main column of <span>content</span></p>
</block>
Et une partie de ma classe ressemble à ceci:
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;
}
Je l'ai travailler la façon dont je veux en ce qu'elle attrape chaque <bloc> sur la la page et injecte son contenu dans mon modèle, cependant, il est dépouillant les balises HTML dans le bloc < >, revenant ainsi ce qui suit sans <p> ou < durée > tags:
this is some rendered PHP! Main column of content
Qu'est-ce que je fais mal ici? :) Merci