如何通过PHP脚本将PHP文件包含在html文件中 [英] How to include a php file in a html file via a php script
问题描述
我之前已经发过这个问题,但人们总是提出不必要的问题。我将以一种简单的方式解释它。
I already post this question before but people always ask unnecessary question. I'm gonna explain it in a simple way.
我有 3 文件:
- 一个php文件(只包含html,这很重要):我们称之为X文件为例。
- 一个php文件,其中有一些数据库查询在屏幕上插入数据库数据:Y文件
- 一个php文件(将进行一些操作的脚本):Z文件
所以,我希望将 Y 包含在 X 中,并使用 Z 的脚本。
SO, i want to include Y into X with the script of Z.
在 Z 中,我创建一个 str_replace($ text,$ new,file_get_contents($ file));
唯一的问题是我需要在 X 中包含PHP打开和关闭TAGS,因为其中没有php标记。
The ONLY THING is that i need to include PHP open and close TAGS in X because there's no php tags in it.
所以, $ new =<?php include('Y.php');?>;
。
如果你尝试,不会在字符串中考虑关闭标记,但这就是我想要的。
So, $new = "<?php include('Y.php'); ?>";
.
If you try, the close tag wont be considered in the string, but that's what i want.
希望这个问题现在清楚。我不能比那更清楚。 :D
Hope this question is NOW clear. I can't be more clearer than that. :D
谢谢你的建议。
推荐答案
问题是非常不清楚和模糊,但我猜测:
The question is very unclear and vague, but I have a guess:
文件X是一些HTML,你想要替换特殊标记。
文件Y加载来自DB的值应该替换标记。
文件Z进行替换。
File X is some HTML where you want to replace special markers.
File Y loads the value from DB that should replace the marker.
File Z does the replacement.
这可以解决(文件Z):
This could be solved like that (File Z):
<?php
ob_start();
include("Y.php");
$repl = ob_get_contents();
ob_end_clean();
ob_start();
include("X.php");
$src = ob_get_contents();
ob_end_clean();
echo str_replace("THEREPLACEMENTMARKER", $repl, $src);
?>
这篇关于如何通过PHP脚本将PHP文件包含在html文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!