2

I want to grab a php file, evaluate any php, then store the contents in a variable.

We'll call this.. page.php

<?php
$content = "Hello World.";
?>

<html>
<head>
<title><?php echo $content ?></title>
</head>
<body>
<?php echo $content ?>
</body>
</html

And I want to put that into a variable by calling a function from another file.

Luke Burns
  • 1,911
  • 3
  • 24
  • 30

2 Answers2

1

Use ob_start() before including the file, and ob_get_clean() after.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

PHP can evaluate any string as a PHP code with function eval; http://php.net/manual/en/function.eval.php

Hydrino
  • 567
  • 3
  • 9