I want to require/include a file and retrieve its contents into a variable.
test.php
You can write in the included file:
<?php
return 'seconds etc.';
And in the file from which you are including:
<?php
$text = include('file.php'); // just assigns value returned in file
Use shell_exec("php test.php"). It returns the output of the execution.
If your included file returned a variable...
<?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();