有没有可能做这样的东西?
// 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>
我知道代码不会工作,但我希望你能理解我的意思。
发布于 2012-01-06 07:07:27
file.php
ob_start();
include 'otherfile.php';
$string = ob_get_clean();
发布于 2012-01-06 07:10:37
$string = file_get_contents('otherfile.php',TRUE);
echo $string
对file_get_contents()使用TRUE参数意味着它将使用包含路径进行搜索,就像普通的包含或要求
发布于 2012-01-06 07:09:47
另一件很酷的事情是,SmokeyPHP的答案可能更好:
<?php
$var = require 'myfile.php';
myfile.php:
<?php
return 'mystring';
https://stackoverflow.com/questions/8751182
复制相似问题