dongwei4444 2013-10-23 11:38
浏览 51
已采纳

从另一个php文件中读取一个php文件

I currently have a php file that I'm using as a template but I need it to read in data from another php file that I'm using for the page content. I'm doing it this way to save on code and time, however it doesn't appear to be working. I have done a test with shorter amounts of code but it still isn't working. they are both .php files.

Code -

<html>
<head>
    <title></title>
</head>
<body>
    <?php 
        $temp = 'test-2.php';
        $file = fopen($temp, 'r');
        $cont = fread($file, filesize($temp));
        print $cont;
        fclose($file);
    ?>
</body>

test-2.php

<?php
echo 'hello world';
?>
  • 写回答

1条回答 默认 最新

  • duan89197 2013-10-23 11:40
    关注

    just use <?php include('test-2.php'); ?> surely that'll do what you want?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?