dongzhanjuan5141
dongzhanjuan5141
2015-12-11 10:08

在file_get_contents中获取变量('file.php')[重复]

已采纳

This question already has an answer here:

I have a file called file.php with this content:

<?php

$foo = 'hello';

?>
<div id="fileContent">
   <?php echo($foo) ?>
  ...some content here
</div>

In other file called result.php, I call the file.php with the method file_get_contents():

<div id="resultContent">
  <?php echo(file_get_contents('file.php')) ?>
</div>

But, I can´t print the internal variable $foo in my result.php file. Only appears as:

<!--?php echo($q); ?-->

Can I get this result? //print hello in the result.php file

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doutang1873 doutang1873 6年前

    file_get_contents() reads the specified file byte by byte but does not interpret it's contents. What you are searching for is the include() directive:

    <div id="resultContent">
      <?php include('file.php') ?>
    </div>
    
    点赞 评论 复制链接分享
  • douxie1894 douxie1894 6年前

    use include() instead file_get_contents()

    点赞 评论 复制链接分享

相关推荐