How do I load a PHP file into a variable?


Question

I need to load a PHP file into a variable. Like include();

I have loaded a simple HTML file like this:

$Vdata = file_get_contents("textfile.txt");

But now I need to load a PHP file.

1
90
7/15/2010 5:51:38 PM

Accepted Answer

I suppose you want to get the content generated by PHP, if so use:

$Vdata = file_get_contents('http://YOUR_HOST/YOUR/FILE.php');

Otherwise if you want to get the source code of the PHP file, it's the same as a .txt file:

$Vdata = file_get_contents('path/to/YOUR/FILE.php');
113
8/13/2009 4:48:02 PM

ob_start();
include "yourfile.php";
$myvar = ob_get_clean();

ob_get_clean()


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon