php缓冲区探析

缓冲区用到的3个函数:

1.ob_start();
2.$buffer = ob_get_contents();
3.ob_end_clean();

用法示例:CI框架 system/core/Exceptions.php   Ci_Exceptions 的show_error方法

/**
 * General Error Page
 *
 * Takes an error message as input (either as a string or an array)
 * and displays it using the specified template.
 *
 * @param  string    $heading   Page heading
 * @param  string|string[]    $message   Error message
 * @param  string    $template  Template name
 * @param  int       $status_code   (default: 500)
 *
 * @return string Error page output
 */
public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
   $templates_path = config_item('error_views_path');
   if (empty($templates_path))
   {
      $templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
   }


   if (is_cli())
   {
      $message = "\t".(is_array($message) ? implode("\n\t", $message) : $message);
      $template = 'cli'.DIRECTORY_SEPARATOR.$template;
   }
   else
   {
      set_status_header($status_code);
      $message = '<p>'.(is_array($message) ? implode('</p><p>', $message) : $message).'</p>';
      $template = 'html'.DIRECTORY_SEPARATOR.$template;
   }


   if (ob_get_level() > $this->ob_level + 1)
   {
      ob_end_flush();
   }
   ob_start();
   include($templates_path.$template.'.php');
   $buffer = ob_get_contents();
   ob_end_clean();
   return $buffer;
}


未完待续。。。。。。。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值