php ob gzhandler:php ob_start()与ob_gzhandler()
output control 函数可以让你自由控制脚本中数据的输出。它非常地有用,特别是对于:当你想
在数据已经输出后,再输出文件头的情况。输出控制函数不对使用 header() 或 setcookie(),
发送的文件头信息产生影响,只对那些类似于 echo() 和 php 代码的数据块有作用。
我们先举一个简单的例子,让大家对output control有一个大致的印象:
example 1.
-------------------------------------------------------------------------------------
---------------------------------
ob_start(); //打开缓冲区
echo "hello\n"; //输出
header(“location:index.php”); //把浏览器重定向到index.php
ob_end_flush();//输出全部内容到浏览器
?>
-------------------------------------------------------------------------------------
---------------------------------
所有对header()函数有了解的人都知道,这个函数会发送一段文件头给浏览器,但是如果在使用
这个函数之前已经有了任何输出(包括空输出,比如空格,回车和换行)就会提示出错。如果我
们去掉第一行的ob_start(),再执行此程序,我们会发现得到了一条错误提示:“header had
all ready send by”!但是加上ob_start,就不会提示出错,原因是当打开了缓冲区,echo后面
的字符不会输出到浏览器,而是保留在服务器,直到你使用flush或者ob_end_flush才会输出,所
以并不会有任何文件头输出的错误!
一、 相关函数简介:
1、flush:刷新缓冲区的内容,输出。
函数格式:flush()
说明:这个函数经常使用,效率很高。
2、ob_start :打开输出缓冲区
函数格式:void ob_start(void)
说明:当缓冲区激活时,所有来自php程序的非文件头信息均不会发送,而是保存在内部缓冲区。
为了输出缓冲区的内容,可以使用ob_end_flush()或flush()输出缓冲区的内容。
3 、ob_get_contents :返回内部缓冲区的内容。
使用方法:string ob_get_contents(void)
说明:这个函数会返回当前缓冲区中的内容,如果输出缓冲区没有激活,则返回 false 。
4、ob_get_length:返回内部缓冲区的长度。
使用方法:int ob_get_length(void)
说明:这个函数会返回当前缓冲区中的长度;和ob_get_contents一样,如果输出缓冲区没有激
活。则返回 false。
5、ob_end_flush :发送内部缓冲区的内容到浏览器,并且关闭输出缓冲区。 本文链接http://www.cxybl.com/html/wlbc/Php/20120531/27127.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to docker start failure: 1. Check the running status, and then release the occupied memory through the "echo 3 > /proc/sys/vm/drop_caches" command; 2. Use "$netstat -nltp|grep .. ." command to check whether the port has been occupied. If it is found to be occupied after going online, change it to an available port and restart.

The Linux header refers to the beginning of a file or data stream, which is used to contain metadata about the content. By correctly writing and using Header files, developers can better utilize system resources and improve code readability and Maintainability.

[SpringBoot] Passing parameters in the Header through Feign calls How to pass Header parameters through Feign Problem description When we use Feign to request the Api interface of another service in Spring Cloud, there is a need to pass the parameters in the Header. If no special processing is done, it will The parameters in the Header will be lost. Solution 1: Pass it through @RequestHeader(name="headerName"). For example: Feign is defined as follows @FeignClient(name="service-name")pub

PHP is a powerful programming language that can be used to create dynamic websites and web applications. One of the most powerful features is PHP’s header() method. In this article, we will explore how to use PHP’s header() method to adjust web pages.

Differences: 1. The head tag is used to define the head of the document, which is a container for all head elements, and the header tag is used to define the header (introduction information) of the document; 2. All browsers support the head tag, and older versions of browsers None of the browsers support the header tag, and browsers such as IE9+ and above are required to support the header tag.

How to implement jump in php header: 1. Use "Header("Location:$url");" syntax to implement jump; 2. Use if judgment to implement jump, with jump statements such as "if($_COOKIE[" u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');".

Nginx can distribute requests to different servers based on custom identifiers in the request headers. Specifically, you can use the map directive to map the custom identifier in the request header to a different backend server address, and then use the proxy_pass directive to forward the request to the corresponding backend server. The following is an example configuration file: http{map$http_my_header$backend{defaultbackend1.example.com;value1backend2.example.com;value2backend3.example.com;}upstreambackend1{serv

Complete list of PHP file download functions: File download example analysis of readfile, header, Content-Disposition and other functions. File download is one of the essential functions in Web applications, and PHP, as a widely used Web development language, provides many A function and method to implement file downloading. This article will introduce commonly used file download functions in PHP, including readfile, header, Content-Dispo
