需要来自可变内容而不是文件


require from variable content instead of a file

通常我写的缓存文件的内容如下:

<html>
<head>
<title><?= $foo; ?></title>
</head>
<body>
<p><?= $content; ?></p>
</body>
</html>

然后我写缓存文件:

<?php
file_put_contents('cache_file.php', $aboveContent);

然后我require他们喜欢:

<?php
require 'cache_file.php';

但现在,如果我不能写入缓存文件(例如,在应该写入文件的目录上没有写入权限,或者在开发中不需要e.x缓存),那么我喜欢直接要求变量内容(它保存缓存文件的文件内容)。

这有可能吗?我没有找到实现这一点的方法。或者我应该写到PHP的临时目录并再次从那里要求吗?

分配给一个变量并回显它:

$content = <<<EOF
<html>
<head>
<title>$foo</title>
</head>
<body>
<p>$content</p>
</body>
</html>
EOF;
echo $content;