How to assign the contents of a file to a variable in PHP

前端 未结 7 730
Happy的楠姐
Happy的楠姐 2020-12-30 07:22

I have a document file containing HTML markup. I want to assign the contents of the entire file to a PHP variable.

I have this line of code:

$body = in

7条回答
  •  没有蜡笔的小新
    2020-12-30 07:52

    You should be using file_get_contents():

    $body1 = file_get_contents('email_template.php');
    

    include is including and executing email_template.php in your current file, and storing the return value of include() to $body1.

    If you need to execute PHP code inside the of file, you can make use of output control:

    ob_start();
    include 'email_template.php';
    $body1 = ob_get_clean();
    

提交回复
热议问题