php:输出缓冲区处理函数用法总结

伊谢尔伦
发布: 2023-03-11 10:10:01
原创
1405 人浏览过

输出缓冲区处理函数的作用有点类似C的堆栈,临时放入一个存储空间中,对内容进行处理。

输出缓冲区函数有:

  • ob_start() - 打开输出控制缓冲

  • ob_get_length() - 返回输出缓冲区的长度

  • ob_get_level() - 返回输出缓冲区的嵌套级别

  • ob_get_status() - 返回输出缓冲区的状态(数组形式返回,默认返回最顶层,参数为true时返回所有)

  • ob_get_contents() - 返回输出缓冲区的内容

  • ob_get_clean() - 以字符串格式返回当前输出缓冲区并关闭输出缓冲

  • ob_end_clean() - 清空(擦除)缓冲区并关闭输出缓冲

  • ob_get_flush() - 以字符串返回输出缓冲区内容并关闭缓冲

  • ob_end_flush() - 冲刷出(送出)输出缓冲区内容缓冲

实例如下:

<?php  
 define(&#39;APP_ROOT&#39;, dirname(FILE));
 $file = &#39;/templates/html/error_config.html&#39;;
 ob_start(); 
 include(APP_ROOT.$file);
 ob_end_flush();
   //$contents = ob_get_contents();  这样可以将输出保存,可以作进一步处理
  //ob_end_clean();
   //echo $contents;
 ?>
登录后复制
<?php echo"<?xml version=\"1.0\" encoding=\"utf-8\">"; ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD  XHTML 1.0  Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <meta http-equiv="Content-Script-Type" content="text/javascript" />
     <meta http-equiv="Content-Style-Type" content="text/css" />
     <title>Error</title>
 </head>
 <body onload="doRedirect()">
 <h1>Error</h1>
 <div style="position:absolute;top:150px;text-align:center;width:95%;">
     <p style="margin:12pt;"><strong>config.php</strong> does not exist or is not readable by the webserver in the directory.</p>
     <p style="margin:12pt;"><?php echo CommonFunctions::$PSI_VERSION_STRING ?></p>
 </div>
 </body>
 </html>
登录后复制

输出结果如下:

config.php does not exist or is not readable by the webserver in the phpsysinfo directory.
登录后复制

 

 

 

以上是php:输出缓冲区处理函数用法总结的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!