如何添加php标签与dom解析器 [英] how to add php tags with the dom parser
本文介绍了如何添加php标签与dom解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一些PHP模板与php doms功能,
现在我喜欢添加一些php标签到我的模板
ie
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('input');
$input->setAttribute("type", "text");
$input->setAttribute("name", $name);
$input->setAttribute("class", "input");
$input->setAttribute("id", $name);
$input->setAttribute("value", '<?=$foo->bar; ?>');
我的问题是,dom解析器逃避php线..
my problem is, that the dom parser escape the php line..
<input type="text" name="id" class="input" id="id" value="\<?=$content->id;?>" />
有另一种方法吗?
推荐答案
您需要处理说明
$php = $dom->createProcessingInstruction('php', 'echo $foo->bar;');
完整示例:
$dom = new DOMDocument;
$dom->loadXml('<html><head><title>Test</title></head><body/></html>');
$dom->getElementsByTagName('body')->item(0)->appendChild(
$dom->createProcessingInstruction('php', 'echo $foo->bar;')
);
$dom->format = TRUE;
echo $dom->saveXML();
结果:
<?xml version="1.0"?>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php echo $foo->bar;?>
</body>
</html>
这篇关于如何添加php标签与dom解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文