类似于 file_get_contents() 但它仍应执行 PHP 代码。这可能吗-6ren">
sách gpt4 ăn đã đi

php - 要求/包含到变量中

In lại 作者:IT王子 更新时间:2023-10-28 23:56:32 29 4
mua khóa gpt4 giày nike

我想要求/包含一个文件并将其内容检索到一个变量中。

test.php

echo "seconds passed since 01-01-1970 00:00 GMT is ".time();
?>

index.php

$test=require("test.php");
echo "the content of test.php is:
".$test;
?>

类似于 file_get_contents() 但它仍应执行 PHP 代码。这可能吗?

câu trả lời hay nhất

如果您包含的文件返回了一个变量...

include.php

return 'abc';

...然后您可以将它分配给这样的变量...

$abc = include 'include.php';

否则,使用输出缓冲。

ob_start();
include 'include.php';
$buffer = ob_get_clean();

关于php - 要求/包含到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5948395/

29 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress