<?php namespace Pangu\web; use yii\base\Component; /** * html格式响应内容格式化 * @author zhouzhian * */ class HtmlResponseFormatter extends \yii\web\HtmlResponseFormatter { /** * 格式化响应内容 */ public function format($response) { if (stripos($this->contentType, ‘charset‘) === false) { $this->contentType .= ‘; charset=‘ . $response->charset; } $response->getHeaders()->set(‘Content-Type‘, $this->contentType); if ($response->data !== null) { $tmplContent = $response->data; // 去除html空格与换行 $find = array("~>\s+<~","~>(\s+\n|\r)~"); $replace = array(‘><‘,‘>‘); $tmplContent = preg_replace($find, $replace, $tmplContent); $response->content = $tmplContent; } } }
时间: 2024-10-05 04:01:48