我在项目中使用这样的功能:
include ("blocks/myCompanyCommentsListBlock.php");
我需要这样的东西:
$str = sprintf("<div>%s</div>", include ("blocks/myCompanyCommentsListBlock.php"));
如何做到这一点? :)任何链接都很有用:)
答案 0 :(得分:4)
使用输出缓冲来阻止其内容发送到浏览器。然后使用ob_get_clean()
将其输出捕获到变量中。
ob_start();
include ("blocks/myCompanyCommentsListBlock.php");
$content = ob_get_clean();
$str = sprintf("<div>%s</div>", $content);