---
title: "php ob_start 与 ob_end_flush()"
author: "dimingchan"
date: "2010-11-25T15:02:46Z"
tags: []
categories: ["编程语言"]
slug: "php-ob-start-ob-end-flush"
draft: false
lastmod: "2010-11-25T15:02:46Z"
id: 824532
url: "https://dimingchan.iteye.com/blog/824532"
---

本文章主要讲关于php缓冲输出函数php ob_start 与 ob_end_flush()哦

 　　相关函数说明
　　 ob_start（）- 打开输出缓冲区
　　所有的输出信息不在直接发送到浏览器，而是保存在输出缓冲区里面,可选得回调函数用于处理输出结果信息。
　　 ob_end_flush - 结束（发送）输出缓冲区的内容，关闭输出缓冲区

test.php
　　 <?
　　 function test($str){
　　 return str_replace("php2000","y10k",$str);
　　 }
　　 ob_start("test");
　　 echo "hello php2000";
　　 ob_end_flush();
　　 ?>
　　这个程序在没有输出信息控制的情况下应该输出为
　　 hello php2000
　　但通过指定了输出控制函数后，输出变为
　　 hello y10k
　　在上面的例子中，使用 echo() 的输出内容将会保存在输出缓冲区中，直到调用了 ob_end_flush()或者脚本运行终止， 然后输出信息由自定义的处理函数进行处理（替换里面的字符串）并返回结果。