Executing PHP from FOPENed files.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Executing PHP from FOPENed files.

Post by Gen-ik »

I am currently in the process of creating a standard set of PHP functions that I will be using as my 'template' for any website designs I do. Each site will be built up from different templates a bit like this forum and other phpBB forums.

One thing I am doing is loading a standard .txt file into PHP, replacing various parts using str_replace(), and then trying to get the file (which is now stored in a variable) into the page.

Getting the file into the page is simple if I use echo() but I have <?php ?> sections in the actual file (which is now stored in a variable remember) which I want to execute as normal. At the moment everything between the PHP tags is being displayed on the page as PHP code and isn't being executed.

Any ideas on how I can remedy this? :?


Thanks.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Don't worry I've sorted it...

Code: Select all

<?php

$string = "Some text with <?php echo('php'); ?> in it.";

echo(eval("?>", $string, "<?php"));

?>
Post Reply