php中的ob_start()有什么用? [英] What's the use of ob_start() in php?

查看:66
本文介绍了php中的ob_start()有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ob_start()是否用于output buffering,以便头被缓冲而不发送到浏览器?我在这里有意义吗?如果不是,那为什么我们要使用ob_start()?

Is ob_start() used for output buffering so that the headers are buffered and not sent to the browser? Am I making sense here? If not then why should we use ob_start()?

推荐答案

想到ob_start()时说:开始记住通常会输出的所有内容,但还没有做任何事情."

Think of ob_start() as saying "Start remembering everything that would normally be outputted, but don't quite do anything with it yet."

例如:

ob_start();
echo("Hello there!"); //would normally get printed to the screen/output to browser
$output = ob_get_contents();
ob_end_clean();

通常将其与其他两个功能配对:ob_get_contents(),它基本上为您提供自使用ob_start()打开缓冲区以来已保存"到缓冲区的所有内容,然后是ob_end_clean()ob_flush() ,它们要么停止保存并丢弃所有保存的内容,要么停止保存并立即全部输出所有内容.

There are two other functions you typically pair it with: ob_get_contents(), which basically gives you whatever has been "saved" to the buffer since it was turned on with ob_start(), and then ob_end_clean() or ob_flush(), which either stops saving things and discards whatever was saved, or stops saving and outputs it all at once, respectively.

这篇关于php中的ob_start()有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆