php ob_get_contents,ob_get_contents();用法【转】
下面3个函数的用法
ob_get_contents();
ob_end_clean();
ob_start()
使用ob_start()把输出那同输出到缓冲区,而不是到浏览器。
然后用ob_get_contents得到缓冲区的数据。
ob_start()在服务器打开一个缓冲区来保存所有的输出。所以在任何时候使用echo ,输出都将被加入缓冲区中,直到程序运行结束或者使用ob_flush()来结束。然后在服务器中缓冲区的内容才会发送到浏览器,由浏览器来解析显示。
函数ob_end_clean 会清除缓冲区的内容,并将缓冲区关闭,但不会输出内容。
此时得用一个函数ob_get_contents()在ob_end_clean()前面来获得缓冲区的内容。
这样的话, 能将在执行ob_end_clean()前把内容保存到一个变量中,然后在ob_end_clean()后面对这个变量做操作。
这是EG:
ob_start(); // buf1
echo ' multiple ';
ob_start(); // buf2
echo ' buffers work ';
$buf2 = ob_get_contents();
ob_end_clean();
$buf1 = ob_get_contents();
ob_end_clean();
echo $buf1;
echo '
';
echo $buf2;
ob_get_contents
(PHP 4, PHP 5)
ob_get_contents -- Return the contents of the output buffer
Description
string ob_get_contents ( void )
This will return the contents of the output buffer or FALSE, if output buffering isn't active.
See also ob_start() and ob_get_length().
if you use ob_start with a callback function as a parameter, and that function changes ob string (as in example in manual) don't expect that ob_get_contents will return changed ob.
it will work as you would use ob_start with no parameter at all. So don't be confused.
transfer image, another method (alternative to fsockopen or function socket) :
server(192.168.0.1)
makeimage.php
...........
...........
$nameimage="xxxx.jpg"
$comand=exec("plotvelocity.sh $nameimage $paramater1 $paramater2");
ob_start();
readfile($nameimage);
$image_data = ob_get_contents();
ob_end_clean();
echo $image_data;
unlink($nameimage);
Client (192.168.0.2)
$bild="images/newimage2.gif";
$host="192.168.0.1";
$url=file_get_contents("http://$host/makeimage.php?$querystring");
$fp = fopen("$bild", 'wb');
fwrite($fp, $url);
fclose($fp);
echo '';
naturally you can transfer whichever thing and not only images
ob_get_clean
(PHP 4 >= 4.3.0, PHP 5)
ob_get_clean -- Get current buffer contents and delete current output buffer
Description
string ob_get_clean ( void )
This will return the contents of the output buffer and end output buffering. If output buffering isn't active then FALSE is returned. ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().
例子 1. A simple ob_get_clean() example<?php
ob_start();
echo "Hello World";
$out = ob_get_clean();
$out = strtolower($out);
var_dump($out);
?>
Our example will output: string(11) "hello world"
See also ob_start() and ob_get_contents().
Notice that the function beneath does not catch errors, so throw in an @ before those ob_* calls
Running PHP4 < 4.3.0, you can simply add the following to use the function anyway:
if (!function_exists("ob_get_clean")) {
function ob_get_clean() {
$ob_contents = ob_get_contents();
ob_end_clean();
return $ob_contents;
}
}
?>
php ob_get_contents,ob_get_contents();用法【转】相关推荐
- ob_get_contents()函数的用法
ob_get_contents()函数的用法 来自: 奇鸟软件 2011-05-27 10:40:20 下面3个函数的用法 ob_get_contents(); ob_end_clean(); ob_ ...
- ob_get_contents();basename;file_get_contents用法
ob_get_contents(); ob_end_clean(); ob_start() 使用ob_start()把输出那同输出到缓冲区,而不是到浏览器. 然后用ob_get_contents得到缓 ...
- php缓冲区操作函数,PHP缓冲区的三个函数ob_start();ob_get_contents()
下面3个函数的用法 ob_get_contents(); ob_end_clean(); ob_start(); 使用ob_start()把输出那同输出到缓冲区,而不是到浏览器. 然后用ob_get_ ...
- ob_start ob_end_clean的用法 fetch
2019独角兽企业重金招聘Python工程师标准>>> 今天突然明白了, ob_start ob_end_clean 的用法 ob_start();//缓存开始 echo &quo ...
- 页面静态化2 --- 使用PHP缓存机制来完成页面静态化(上)(ob_flush和flush函数区别用法)...
我们可以使用PHP自带的缓存机制来完成页面静态化,但在这里,需要说明一点,仅靠PHP缓存机制并不能完美的解决页面静态化,往往需要和其他页面静态技术(通常是伪静态技术)结合使用 例子: 当访问一个页面时 ...
- php.ini 关闭输出缓冲,php 输出缓冲 Output Control用法实例详解
本文实例讲述了php 输出缓冲 Output Control用法.分享给大家供大家参考,具体如下: 关于php的输出缓冲,首先要说明的是什么是缓冲(buffer),比如我们通过记事本在编辑文件的时候, ...
- php 调用include 方法,php include的使用法详解
include 语句包含并运行指定文件. 以下文档也适用于 require . 被包含文件先按参数给出的路径寻找,如果没有给出目录(只有文件名)时则按照 include_path 指定的目录寻找.如果 ...
- PHP中的ob_start用法详解
用PHP的ob_start(); 控制您的浏览器cache Output Control 函数可以让你自由控制脚本中数据的输出.它非常地有用,特别是对于:当你想在数据已经输出后,再输出文件头的情况.输 ...
- c语言中external,static关键字用法
static用法: 在C中,static主要定义全局静态变量.定义局部静态变量.定义静态函数. 1.定义全局静态变量:在全局变量前面加上关键字static,该全局变量变成了全局静态变量.全局静态变量有 ...
- Pandas_transform的用法
先来看一个实例问题. 如下销售数据中展现了三笔订单,每笔订单买了多种商品,求每种商品销售额占该笔订单总金额的比例.例如第一条数据的最终结果为:235.83 / (235.83+232.32+107.9 ...
最新文章
- 一个比特币要挖多久?
- Oracle connet by prior 关键字的简单介绍和用法
- C/C++ / 函数调用规则汇总
- Docker与虚拟机
- C++内存分配方式-堆、栈、自由存储区、全局/静态存储区和常量存储区
- vscode 执行npm命令_生产力终极指南:用了两年,如今才算真正会用VS Code
- 阿里 90 后科学家研发,达摩院开源新一代 AI 算法模型
- linux 无损拆分分区 asm,利用UDEV SCSI Rules配置linux下的ASM
- 并查集路径压缩和按rank合并代码实现
- Xiaojie雷达之路---脉冲压缩
- Layui选项卡Tab和Layui模板laytpl冲突问题
- 测试投入度量元的选择
- CPU使用率过高应该如何处理
- 王者荣耀登录显示换服务器是不是封号,王者荣耀这么查看封号原因?千万不要这么做!...
- ptp精准时间协议_精确时间协议PTP研究
- 英文字母间隔很大怎么解决?全角半角的概念
- [紧急]华展云再次连夜更新200余本16年会刊,2016年会刊量级已达全网第一
- 法律部门和法律体系(概念、我国现行的法律部门和法律体系 )、法 律 关 系(概念、构成要素:主体、内容、客体)、法律事实(法律事件、法律行为)
- JSONObject对象常用方法讲解--fromObject和toBean
- 关于使用ADS编译很卡的问题