如何实施'包括'进入printf?

时间:2014-02-17 21:25:44

标签: php

我在项目中使用这样的功能:

include ("blocks/myCompanyCommentsListBlock.php");

我需要这样的东西:

$str = sprintf("<div>%s</div>", include ("blocks/myCompanyCommentsListBlock.php"));

如何做到这一点? :)任何链接都很有用:)

1 个答案:

答案 0 :(得分:4)

使用输出缓冲来阻止其内容发送到浏览器。然后使用ob_get_clean()将其输出捕获到变量中。

ob_start();
include ("blocks/myCompanyCommentsListBlock.php");
$content = ob_get_clean();
$str = sprintf("<div>%s</div>", $content);