发布日期:2018-03-26
在php中ob_start()如何使用?+ 查看更多
在php中ob_start()如何使用?
+ 查看更多
发布日期:2018-03-07 15:55
分类:PHP
浏览次数:107
ob_start()是否用于输出缓冲,能将输出缓冲至内存而不发送到浏览器? 这样做有意义吗? 如果无意义那么为什么我们要使用ob_start()?
回答
ob_start()的意义为:“开始记住正常情况下的一切输出数据,但是不要输出(暂存在内存中)。”
例如:
ob_start(); echo("Hello there!"); //would normally get printed to the screen/output to browser $output = ob_get_contents(); ob_end_clean();还有另外三个函数,经常与ob_start()配合使用: ob_get_contents():它将返回从ob_start()开启缓冲区后已经“保存”在缓冲区的内容 ob_end_clean():停止缓存内容并丢弃已经缓存的内容 ob_flush():停止缓存并将缓存中的数据一次性输出。