有可能做出这样的事吗?
// 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>
Run Code Online (Sandbox Code Playgroud)
得到这个输出?
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<p>Lorem ipsum something</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我知道代码不起作用,但我希望你理解我的意思.
Smo*_*PHP 53
file.php
ob_start();
include 'otherfile.php';
$string = ob_get_clean();
Run Code Online (Sandbox Code Playgroud)
Mar*_*ker 11
$string = file_get_contents('otherfile.php',TRUE);
echo $string
Run Code Online (Sandbox Code Playgroud)
对file_get_contents()使用TRUE参数意味着它将使用包含路径进行搜索,就像普通包含或要求一样