是否有可能做出类似这样的事情?包含PHP文件作为字符串
// file.php
$string = require('otherfile.php');
echo $string;
// otherfile.php
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<?php require 'body.php';?>
</body>
</html>
// body.php
<p>Lorem ipsum something</p>
并得到这个输出?
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<p>Lorem ipsum something</p>
</body>
</html>
我知道代码不起作用,但我希望你明白我的意思。
参见:http://stackoverflow.com/questions/1683771/execute-a-php-file-and-return-the-result-as-a-string – BeRecursive 2012-01-05 23:06:45
这看起来有点像你正在重新发明模板。也许你可以使用模板引擎? – 2012-01-05 23:11:21
我认为模板引擎重新发明PHP,但它是一个意见的问题:) – Yaniro 2012-01-05 23:14:05