-2

I am loading content into a PHP page by fetching the content from other files. These files are structured like XML:

<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>

I am loading the content file into a DOMDocument so that I can retrieve the parts of the page and insert them in the correct place (e.g. the stylesheets go in the head of the PHP page the content is being inserted into, and the content goes in a specific div on the page)

This has worked well so far.

However, if I put PHP code into the content, it does not execute when the content is inserted:

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

Is there a way I can structure my file like this so that I can pull different parts of the file out and insert them in various places in my main PHP file, whilst allowing any PHP code in these content files to get executed when it gets inserted? Or is there a better way to do this.

I apologise in advance for how verbose the question is, but I thought it would be better to add too much information than be vague.

Thanks in advance!

4

1 回答 1

0

您可以使用 phpeval()函数在文本中执行 php。但我不确定这是一种安全的方法。

您可以在此处查看 PHP 手册:

http://php.net/manual/en/function.eval.php

于 2013-08-04T00:02:44.393 回答