是否有可能做出類似這樣的事情?包含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