我试图将包含的内容添加到字符串中.那可能吗?
例如,如果我有一个test.php文件:
echo 'a is equal to '.$a;
Run Code Online (Sandbox Code Playgroud)
我需要一个函数,比如说include_to_string包含test.php并返回字符串输入的内容.
就像是:
$a = 4;
$string = include_to_string(test.php); // $string = "a is equal to 4"
Run Code Online (Sandbox Code Playgroud)
Dav*_*dom 32
ob_start();
include 'test.php';
$string = ob_get_clean();
Run Code Online (Sandbox Code Playgroud)
我想是你想要的.请参阅输出缓冲.
ob_start();
include($file);
$contents = ob_get_contents(); // data is now in here
ob_end_clean();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12340 次 |
| 最近记录: |