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. I HAVE 3 files : a php file (contains only html, thats import
Solution 1:
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()
Solution 2:
The question is very unclear and vague, but I have a guess:
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.
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);
?>
Post a Comment for "How To Include A Php File In A Html File Via A Php Script"