В соответствии с упомянутым здесь процессом https://www.tkcodez.info/minify-html-output-via-php-code/. Я попытался внедрить один скрипт в один из моих файлов макета, например:
// Layout.phtml
<?php
function sanitize_output($buffer) {
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $buffer);
return $buffer;
}
ob_start("sanitize_output");
?>
<!doctype html>
<html>
<head>
<meta charset = "utf-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<?php /*?><meta name = "verify-v1" content = "zXRjEY50qXN7Oxbt0tAIDegKmUk5nG32qLmAzMuZSw0 = " /><?php */?>
<meta name = "google-site-verification" content = "J-w0iienSxG8y23RN-NYZ0oh4y9YBygvb-ealpBmBi0" />
<?php
$controllerName = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$actionName = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
$popupsessionTutor = new Zend_Session_Namespace('Popup_Session_Tutor');
$popupsessionCenter = new Zend_Session_Namespace('Popup_Session_Center');
?>
---- rest of the phtml file -----
Но не смог найти мой исходный код просмотра html в уменьшенном виде. Что мне еще нужно делать?
Хорошо ... Я отредактировал свой вопрос. Пожалуйста, проверьте и дайте мне знать.






Поскольку вы используете ZF1 и предполагаете, что MVC и то, что вы разместили, является сценарием просмотра, вы можете написать плагин контроллера, который определяет метод dispatchLoopShutdown, который выполняет желаемую модификацию ответа.
<?php
class My_Controller_Plugin_Sanitize extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$body = preg_replace($search, $replace, $this->getResponse()->getBody());
$this->getResponse()->setBody($body);
unset($body);
}
}
Просить сообщество найти библиотеки не следует здесь, в Stack Overflow. Подробнее читайте здесь: stackoverflow.com/help/on-topic