how to add php tags with the dom parser

前端 未结 1 1552
盖世英雄少女心
盖世英雄少女心 2021-01-13 06:16

I create some HTML Templates with php doms functionality, now i like to add some php tags into my template i.e.

$input = $this->dom->createElement(\'in         


        
1条回答
  •  一向
    一向 (楼主)
    2021-01-13 06:38

    You need a Processing Instruction

    $php = $dom->createProcessingInstruction('php', 'echo $foo->bar;');
    

    Full example:

    $dom = new DOMDocument;
    $dom->loadXml('Test');
    $dom->getElementsByTagName('body')->item(0)->appendChild(
        $dom->createProcessingInstruction('php', 'echo $foo->bar;')
    );
    $dom->format = TRUE;
    echo $dom->saveXML();
    

    Result:

    
    
      
        Test
      
      
        bar;?>
      
    
    

    0 讨论(0)
提交回复
热议问题