Jump to content

Archived

This topic is now archived and is closed to further replies.

glenelkins

is this possible?

Recommended Posts

consider the following code

[code]
$file_handle = fopen($template,"r");
$template = fread($file_handle,filesize($template));
fclose ($file_handle);

$file_handle = fopen($module,"r");
$module = fread($file_handle,filesize($module));
fclose ($file_handle);

$template = eregi_replace ("{module}",$module,$template);

// Show the template
echo $template;
[/code]

Ok so assuming $module is "home.html" this will replace the tag {module} in the template HTML file with whatever is in home.html. But what is $module was "home.php" and I wanted to replace {module} with the php code to run, usually include("home.php") would do this but how would I user this code above to get the script to  replace {module} with the include command and actuall make it run the php code?

Share this post


Link to post
Share on other sites
You can't use fread to execute PHP code since it literally reads a string and doesn't parse the code.

When you include the page the PHP engine parses through the code executing it as it goes along. With the fread function it would just see a massive string with <?php at the beginning but it wouldn't parse it.

Share this post


Link to post
Share on other sites
[quote author=coldkill link=topic=111486.msg451870#msg451870 date=1160839615]
You can't use fread to execute PHP code since it literally reads a string and doesn't parse the code.

When you include the page the PHP engine parses through the code executing it as it goes along. With the fread function it would just see a massive string with <?php at the beginning but it wouldn't parse it.
[/quote]

Like coldkill said you can't execute a PHP page.  You can't even execute a HTML page with fread() [unless opening a URL].  To put it in more simple terms, It can only only read plain text, the source code, and URL's too.

If you want to learn know more look here:

[url=http://www.php.net/manual/en/function.fread.php]http://www.php.net/manual/en/function.fread.php[/url]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.