Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load a PHP file into a variable?

Tags:

file

php

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.

like image 412
Kombuwa Avatar asked Aug 13 '09 14:08

Kombuwa


People also ask

How do I load a PHP file?

php" file extension. Open up any Web browser on your desktop and enter "localhost" into the address box. The browser will open a list of files stored under the "HTDocs" folder on your computer. Click on the link to a PHP file and open it to run a script.

What is $_ in PHP?

PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL.


2 Answers

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

ob_get_clean()

like image 158
neobie Avatar answered Oct 06 '22 17:10

neobie


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'); 
like image 22
Alix Axel Avatar answered Oct 06 '22 15:10

Alix Axel