include - How to assign the contents of a file to a variable in PHP -
i have document file containing html markup. want assign contents of entire file php variable.
i have line of code:
$body = include('email_template.php');
when var_dump()
string(1) "'"
is possible assign contents of file variable?
[note: reason doing want separate body segment of mail message mailer script -- sort of template user modifies html markup , not need concerned mailer script. including file entire body segment on mail($to, $subject, $body, $headers, $return_path);
thanks.
if there php code needs executed, indeed need use include
. however, include
not return output file; emitted browser. need use php feature called output buffering: captures output sent script. can access , use data:
ob_start(); // start capturing output include('email_template.php'); // execute file $content = ob_get_contents(); // contents buffer ob_end_clean(); // stop buffering , discard contents
Comments
Post a Comment