Reputation:
I have the following problem within the following script
PHP code:
$var = file_get_contents('template/default/index.php');
$content1 = str_replace('{php}','<?php',$var);
$content2 = str_replace('{/php}','?>',$content1);
echo $content2;
template/default/index.php code:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
{php} echo 'worked'; {/php}
</body>
</html>
I'm trying to transform the {php}{/php} tags within the template/default/index.php to propper php tags. This actually happends, but the php code gets commented out. The browser gives this in return:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<!--?php echo 'worked'; ?-->
Does anybody know how to solve this?
Upvotes: 1
Views: 799
Reputation: 146302
I see no reason to do any of this.
Just use <?php
and ?>
in your index.php file instead of {php}
and {/php}
and then just include the file in your script.
Upvotes: 2
Reputation: 2093
Instead of echoing out the replaced content, it should be eval
'd. Although I don't recommend that.
Upvotes: 7