Search code examples
phpfile

How do I load a PHP file into a variable?


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.


Solution

  • 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');