How do I load a PHP file into a variable?

后端 未结 8 1437
清歌不尽
清歌不尽 2020-11-30 19:20

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(\"text         


        
相关标签:
8条回答
  • 2020-11-30 20:02

    If you are using http://, as eyze suggested, you will only be able to read the ouput of the PHP script. You can only read the PHP script itself if it is on the same server as your running script. You could then use something like

    $Vdata = file_get_contents('/path/to/your/file.php");
    
    0 讨论(0)
  • 2020-11-30 20:06

    Theoretically you could just use fopen, then use stream_get_contents.

    $stream = fopen("file.php","r");
    $string = stream_get_contents($stream);
    fclose($stream);
    

    That should read the entire file into $string for you, and should not evaluate it. Though I'm surprised that file_get_contents didn't work when you specified the local path....

    0 讨论(0)
提交回复
热议问题