require/include into variable

If your included file returned a variable…

include.php

<?php
return 'abc';

…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();

Leave a Comment