i am trying to include a php file. This contains some html and css. These print fine but the php within the file is ignored? :nono:
$template = file_get_contents('template.php');
if you want the php code to be executed, use include
If you want to capture the output, wrap it in ob_start() and ob_get_clean()
$template = include('template.php');
can the above code be assigned to the $template variable or is that wrong?
That would work.
See the docs.
i tried it and it now shows the php...however i noticed another thing, it makes it ignore another bit of code which is
$page = preg_replace('/##CONTENT##/', $content, $template);
when i leave it at $template = file_get_contents('template.php'); the preg_replace works but the PHP code doesnt and when i replace file_get_contents with include the PHP in the works but the content in preg replace doesnt show
is there a way to make them both show
The way is not to mix two technologies.
If you want your template to be PHP code, do not place there such things like /##CONTENT##/
But just substitute it with
<?php echo $content ?>
Are you sure? $template would either include 1, or a value return()d from the included file, but not the contents of that file.