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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.