通过输出缓冲捕获包含文件中打印的任何内容
ob_start();
include 'yourFile.php';
$out = ob_get_contents();
ob_end_clean();
Run Code Online (Sandbox Code Playgroud)
或者,在脚本中设置返回值,例如
// included script
return 'foo';
// somewhere else
$foo = include 'yourFile.php';
Run Code Online (Sandbox Code Playgroud)
参见http://de2.php.net/manual/en/function.include.php的例5
| 归档时间: |
|
| 查看次数: |
1853 次 |
| 最近记录: |