一起源码网

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
猜你喜欢
查看: 7989|回复: 1
打印 上一主题 下一主题

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

[复制链接]

0

主题

0

帖子

1万

积分

钻石会员

Rank: 8Rank: 8

积分
17424
QQ
跳转到指定楼层
楼主
发表于 2020-3-2 07:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
输出缓冲区处理函数的作用有点类似C的堆栈,临时放入一个存储空间中,对内容进行处理。

输出缓冲区函数有:

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

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

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

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

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

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

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

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

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

实例如下:

<?php  
 define('APP_ROOT', dirname(FILE));
 $file = '/templates/html/error_config.html';
 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>
 <p 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>
 </p>
 </body>
 </html>

输出结果如下:

config.php does not exist or is not readable by the webserver in the phpsysinfo directory.

分享到:  QQ好友和群QQ好友和群
收藏收藏
回复

使用道具 举报

0

主题

17

帖子

1万

积分

钻石会员

Rank: 8Rank: 8

积分
16265
QQ
沙发
发表于 2022-9-1 14:45 来自手机 | 只看该作者
音乐平台源码
回复

使用道具 举报

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表