mari — 2010-02-09T12:15:22-05:00 — #1
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');
crmalibu — 2010-02-09T12:30:30-05:00 — #2
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()
mari — 2010-02-09T16:09:49-05:00 — #3
$template = include('template.php');
can the above code be assigned to the $template variable or is that wrong?
anthonysterling — 2010-02-09T16:14:56-05:00 — #4
That would work.
See the docs.
mari — 2010-02-10T04:59:18-05:00 — #5
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
system — 2010-02-10T05:18:02-05:00 — #6
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 ?>
mari — 2010-02-10T05:22:24-05:00 — #7
stormrider — 2010-02-10T08:33:04-05:00 — #8
Are you sure? $template would either include 1, or a value return()d from the included file, but not the contents of that file.