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?

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料