0

Possible Duplicate:
Problem when loading php file into variable (Load result of php code instead of the code as a string)

I am trying to create a template based application and I am having issues writing the user data into a pre-existing template file.

I would initially use file_get_contents('template.php');

and template.php would contain the following:

echo $user;

Is there anyway to insert data into a placeholder variable in a template file using file_get_contents?

I suppose I could use DomDocument or regex to insert the data into a placeholder string, but would this be possible to do with a php variable?

Community
  • 1
  • 1
Kevin Jung
  • 2,973
  • 7
  • 32
  • 35

1 Answers1

0

If you have control over template.php and are aware of the security considerations, you're probably looking for include or require:

include('template.php');

Will do what you want to do.

EDIT

Output buffering

ob_start();
include('template.php');
$result = ob_get_clean();
sleepy_keita
  • 1,488
  • 4
  • 17
  • 26