Jump to content

is this possible?


glenelkins

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?
Link to comment
https://forums.phpfreaks.com/topic/23936-is-this-possible/
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.
Link to comment
https://forums.phpfreaks.com/topic/23936-is-this-possible/#findComment-108808
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]
Link to comment
https://forums.phpfreaks.com/topic/23936-is-this-possible/#findComment-108858
Share on other sites

Archived

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

×
×
  • Create New...

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.