输出缓冲区处理函数的作用有点类似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() - 以字符串返回输出缓冲区内容并关闭缓冲
Build MCP servers and clients for PHP applications with the official PHP SDK下载使用官方Model Context Protocol PHP SDK将PHP应用程序功能暴露为MCP工具、资源和提示,用于代理工作流。
ob_end_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\">"; ?> html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta> <meta> <meta> <title>Error</title> <h1>Error</h1> <div> <p><strong>config.php</strong> does not exist or is not readable by the webserver in the directory.</p> <p><?php echo CommonFunctions::$PSI_VERSION_STRING ?></p> </div>
输出结果如下:
config.php does not exist or is not readable by the webserver in the phpsysinfo directory.
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










