gpt4 book ai didi

php - 将 PHP 文件包含为字符串

转载 作者:IT王子 更新时间:2023-10-28 23:55:05 24 4
gpt4 key购买 nike

有没有可能做出这样的东西?

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

我知道代码行不通,但我希望你明白我的意思。

最佳答案

文件.php

ob_start();
include 'otherfile.php';
$string = ob_get_clean();

关于php - 将 PHP 文件包含为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8751182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com