glenelkins Posted October 14, 2006 Share Posted October 14, 2006 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 templateecho $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? Quote Link to comment Share on other sites More sharing options...
coldkill Posted October 14, 2006 Share Posted October 14, 2006 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 Link to comment Share on other sites More sharing options...
dan245 Posted October 14, 2006 Share Posted October 14, 2006 [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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.