Let me rephrase this question. I'm trying to store the contents of an html
file into a string. I would then like to have the php
code in the html
string convert the php to whatever the values I feed it later. I think the string interpolation might work. I might have over complicated it. But I think it would be interesting to still be able to use php
tags for certain situations.
I would like to do something like this:
$str = 'some words';
$php = '<p><?= $str; ?></p>';
echo $php;
which would output to the DOM
(source):
<p>some words</p>
or simply just on your browser screen
some words
What I get:
<p><!-- <?= $str; ?> --></p>
is this even possible?
I know the code above looks simple but this is just a simple case of the problem I am trying to solve.
<?php
// View
class View {
private static $paths = [];
private static function getTemplate($templatePath) {
if (!array_key_exists($templatePath, self::$paths)) {
// Filename must exist
if (!file_exists($templatePath)) {
die('File Doesn\'t Exist');
}
self::$paths[$templatePath] = file_get_contents($templatePath);
}
return self::$paths[$templatePath];
}
// Fill Template
public static function fill($vars, $templatePath) {
// Turn Vars into unique variables
extract($vars);
$input = self::getTemplate($templatePath);
// Get View Output
ob_start();
echo $input;
$output = ob_get_contents();
ob_end_clean();
return $output;
}
public static function fillWith($templatePath) {
}
}
= $str; ?>
` – Rizier123 Oct 30 '14 at 21:55