我有一个名为file.php的文件,其中包含以下内容:
<?php
$foo = 'hello';
?>
<div id="fileContent">
<?php echo($foo) ?>
...some content here
</div>
在另一个名为result.php的文件中,我使用file_get_contents()方法调用file.php:
<div id="resultContent">
<?php echo(file_get_contents('file.php')) ?>
</div>
但是,我无法在我的result.php文件中打印内部变量$ foo。仅显示为:
<!--?php echo($q); ?-->
我可以得到这个结果吗?//在result.php文件中打个招呼
file_get_contents()逐字节读取指定的文件,但不解释其内容。您要搜索的是include()指令:
<div id="resultContent">
<?php include('file.php') ?>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句