关于ob_get_contents(),ob_end_clean(),ob_start(),的具体用法详解
ob_end_clean();
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()后面对这个变量做操作。
echo"multiple";
ob_start();//buf2
echo"bufferswork";
$buf2=ob_get_contents();
ob_end_clean();
$buf1=ob_get_contents();
ob_end_clean();
echo$buf1;
echo"<br/>";
echo$buf2;
ob_get_contents
(PHP4,PHP5)
ob_get_contents--Returnthecontentsoftheoutputbuffer
Description
stringob_get_contents(void)
ThiswillreturnthecontentsoftheoutputbufferorFALSE,ifoutputbufferingisn"tactive.
Seealsoob_start()andob_get_length().
ifyouuseob_startwithacallbackfunctionasaparameter,andthatfunctionchangesobstring(asinexampleinmanual)don"texpectthatob_get_contentswillreturnchangedob.
itwillworkasyouwoulduseob_startwithnoparameteratall.Sodon"tbeconfused.
transferimage,anothermethod(alternativetofsockopenorfunctionsocket):
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"<imgsrc="".$bild."">";
naturallyyoucantransferwhicheverthingandnotonlyimages
ob_get_clean
(PHP4>=4.3.0,PHP5)
ob_get_clean--Getcurrentbuffercontentsanddeletecurrentoutputbuffer
Description
stringob_get_clean(void)
Thiswillreturnthecontentsoftheoutputbufferandendoutputbuffering.Ifoutputbufferingisn"tactivethenFALSEisreturned.ob_get_clean()essentiallyexecutesbothob_get_contents()andob_end_clean().
<?php
ob_start();
echo"HelloWorld";
$out=ob_get_clean();
$out=strtolower($out);
var_dump($out);
?>
Ourexamplewilloutput:string(11)"helloworld"
Seealsoob_start()andob_get_contents().
Noticethatthefunctionbeneathdoesnotcatcherrors,sothrowinan@beforethoseob_*calls
RunningPHP4<4.3.0,youcansimplyaddthefollowingtousethefunctionanyway:
<?php
if(!function_exists("ob_get_clean")){
functionob_get_clean(){
$ob_contents=ob_get_contents();
ob_end_clean();
return$ob_contents;
}
}
?>
相关文章
- Android listView用法详解
- scikit-learn工具包中分类模型predict_proba、predict、decision_function用法详解「建议收藏」
- webpack性能优化(2):splitChunks用法详解
- 教你如何用Flume监听oracle表增量的步骤详解
- vmware 中linux虚拟机动态添加硬盘详解程序员
- Oracle例外用法实例详解
- [MySQL高级](一) EXPLAIN用法和结果分析详解数据库
- 关于oracle with as用法详解数据库
- Mysql导出(多张表)表结构及表数据 mysqldump用法详解数据库
- jBPM 6 发布,快速安装,新功能介绍详解编程语言
- JAVA网络爬虫抓数据jar包Jsoup的简易用法详解编程语言
- Document.all[]的用法详解编程语言
- Python3.x:bs4解析html基础用法详解编程语言
- js实现当前日期显示详解编程语言
- php ignore_user_abort()实现计划(定时执行)任务功能详解编程语言
- SPRO-MB21设置可用性检查无库存时报错详解编程语言
- The introduction of vbfa详解编程语言
- ABAP:include type与field-symbols的用法详解编程语言
- Django基础学习三_路由系统详解编程语言
- extern关键字,C语言extern关键字用法详解
- C++ priority_queue(STL priority_queue)用法详解
- C++ int,short,long(详解版)
- C++ getline函数用法详解
- MySQL字段描述详解:学会了这些,你就是数据库高手。(mysql字段描述)
- MySQL中的When语句使用详解(mysql中when用法)
- MySQL大全深入探索SQL关键字,不包含用法详解(mysql 不包含用法)
- Redis 原理与机制详解(redis详解原理和机制)
- phpcheckdate、getdate等日期时间函数操作详解