require/include into variable

前端 未结 9 1587
萌比男神i
萌比男神i 2020-11-27 17:46

I want to require/include a file and retrieve its contents into a variable.

test.php



        
9条回答
  •  借酒劲吻你
    2020-11-27 18:35

    If your included file returned a variable...

    include.php

    ...then you can assign it to a variable like so...

    $abc = include 'include.php';
    

    Otherwise, use output buffering.

    ob_start();
    include 'include.php';
    $buffer = ob_get_clean();
    

提交回复
热议问题