dongzhanbi0027 2013-02-20 18:06 采纳率: 0%
浏览 47

如何通过php脚本在PHP文件中包含一个php文件[复制]

This question is an exact duplicate of:

I already post this question before but people always ask unnecessary question. I'm gonna explain it in a simple way.

I HAVE 3 files :

  1. a php file (contains only html, thats important) : We call it X file for the example.
  2. a php file where there's some database query to insert database data on the screen : Y file
  3. a php file (a script that will make some manipulations) : Z file

SO, i want to include Y into X with the script of Z.

In Z, i make a str_replace($text, $new, file_get_contents($file));

The ONLY THING is that i need to include PHP open and close TAGS in X because there's no php tags in it.

So, $new = "<?php include('Y.php'); ?>";. If you try, the close tag wont be considered in the string, but that's what i want.

Hope this question is NOW clear. I can't be more clearer than that. :D

Thanks for you advice.

</div>
  • 写回答

2条回答 默认 最新

  • dongwu8064 2013-02-20 18:14
    关注

    To include a file you do

    <?php
    include(file);
    ?>
    

    So in this case

    X contains <?php include('Y'); ?> And Y contains <?php include('Z') ?>

    But if you are doing what i think you are doing (a template of some sort) you would be better of by looking into overflow buffer ( ob_start and ob_end_flush for example )

    Those can place all echoed information into a variable to be modified later, also the php inside is run, instead of just read as text as in your example with the file_get_contents()

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题