2013-08-03 26 views
-2

我通过从其他文件中获取内容将内容加载到PHP页面中。这些文件的结构,如XML:在DOMDocument中执行PHP代码

<stylesheets> 
    <link rel="stylesheet" type="text/css" href="filepath.css" /> 
    <link rel="stylesheet" type="text/css" href="filepath2.css" /> 
</stylesheets> 

<content> 
    Here is some content which goes into the content div on the page 
</content> 

我加载内容文件到一个DOMDocument这样我可以检索页面的部分,并在正确的位置插入(例如样式表中的头去正在插入内容的PHP页面,并且内容在页面上的特定div中)

迄今为止,这工作得很好。

但是,如果我把PHP代码到内容,它不会在内容插入执行:

<content> 
    <?php echo 'testing php code execution' ?> 
    Here is some content which goes into the content div on the page 
</content> 

有没有一种方法可以让我组织我的文件,这样,这样我可以拉不同部位并将它们插入到我的主PHP文件的各个位置,同时允许这些内容文件中的任何PHP代码在插入时执行?或者有更好的方法来做到这一点。

对于问题的详细程度,我提前表示歉意,但我认为最好是添加太多的信息而不是模糊的。

在此先感谢!

+0

你是说你要http://www.example.com/somefile.xml解析PHP的? – Mike

+0

如果你把它变成一个DOMDocument,你所有的<?php的东西将只是文本。它根本不会被PHP评估。 – MightyPork

+0

好的,我明白了,所以您必须使用include或require来评估PHP代码吗? –

回答