Jump to content


Photo

is this possible?


  • Please log in to reply
2 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 14 October 2006 - 02:37 PM

consider the following 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;

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?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 14 October 2006 - 03:26 PM

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.


You can learn alot from reading the manual

#3 dan245

dan245
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 October 2006 - 06:53 PM

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.


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:

http://www.php.net/m...ction.fread.php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users