odin777 Опубликовано 27 января, 2021 Поделиться Опубликовано 27 января, 2021 Hi, i am trying to minify html output: 1. Create a PHP file (minify.php), with code: <?php function sanitize_output($buffer) { $search = [ '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s', '/<!--(.|\s)*?-->/' ]; $replace = [ '>', '<', '\\1', '' ]; $buffer = preg_replace($search, $replace, $buffer); return $buffer; } ob_start("sanitize_output"); ?> 2. in globaltemplate before <!DOCTYPE html>, i added: {{require "minify.php";}} But it's not working..... Please how to Minify html output?? Цитата Ссылка на комментарий Поделиться на другие сайты Поделиться
Silence Опубликовано 27 января, 2021 Поделиться Опубликовано 27 января, 2021 Download the HTMLMinifier file HTMLMinifier.php Include the following code into the php <?php // Import the HTMLMinifier require_once 'myfolder/HTMLMinifier.php'; // HTML source to be minified $htmlpage = file_get_contents('./mypage.html'); // Minified version of the page echo HTMLMinifier::process($htmlpage); ?> 3.Run the php file or this: function Minify_Html($Html) { $Search = array( '/(\n|^)(\x20+|\t)/', '/(\n|^)\/\/(.*?)(\n|$)/', '/\n/', '/\<\!--.*?-->/', '/(\x20+|\t)/', # Delete multispace (Without \n) '/\>\s+\</', # strip whitespaces between tags '/(\"|\')\s+\>/', # strip whitespaces between quotation ("') and end tags '/=\s+(\"|\')/'); # strip whitespaces between = "' $Replace = array( "\n", "\n", " ", "", " ", "><", "$1>", "=$1"); $Html = preg_replace($Search,$Replace,$Html); return $Html; } or this: <?php ob_start("minifier"); function minifier($code) { $search = array( // Remove whitespaces after tags '/\>[^\S ]+/s', // Remove whitespaces before tags '/[^\S ]+\</s', // Remove multiple whitespace sequences '/(\s)+/s', // Removes comments '/<!--(.|\s)*?-->/' ); $replace = array('>', '<', '\\1'); $code = preg_replace($search, $replace, $code); return $code; } ?> HTMLMinifier.php Цитата Ссылка на комментарий Поделиться на другие сайты Поделиться
odin777 Опубликовано 27 января, 2021 Автор Поделиться Опубликовано 27 января, 2021 Thank you for the fast reply. The instruction not clear enough for me: Include the following code into the php filefilter_none? $htmlpage = file_get_contents('./mypage.html'); Run the php file Please explain Цитата Ссылка на комментарий Поделиться на другие сайты Поделиться
Silence Опубликовано 27 января, 2021 Поделиться Опубликовано 27 января, 2021 1 час назад, Silence сказал: Download the HTMLMinifier file : HTMLMinifier.php Include the following code into the php <?php // Import the HTMLMinifier require_once 'myfolder/HTMLMinifier.php'; // HTML source to be minified $htmlpage = file_get_contents('./mypage.html'); // Minified version of the page echo HTMLMinifier::process($htmlpage); ?> 3.Run the php file Извинете ... оправено SlawkA 1 Цитата Ссылка на комментарий Поделиться на другие сайты Поделиться
odin777 Опубликовано 27 января, 2021 Автор Поделиться Опубликовано 27 января, 2021 Thank you bro, A question: do you have [IPS Marketplace] Minify HTML Output plugin? Цитата Ссылка на комментарий Поделиться на другие сайты Поделиться
Silence Опубликовано 27 января, 2021 Поделиться Опубликовано 27 января, 2021 No ... i have different Trim Empty Lines in Posts 1.0.0.xml Trim Empty Lines in Posts 1.0.0.xml SlawkA 1 Цитата Ссылка на комментарий Поделиться на другие сайты Поделиться
odin777 Опубликовано 27 января, 2021 Автор Поделиться Опубликовано 27 января, 2021 Thank you. I have this one too, anyways, thanks for your support. Цитата Ссылка на комментарий Поделиться на другие сайты Поделиться
Рекомендуемые сообщения
Присоединяйтесь к обсуждению
Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.
Примечание: Ваш пост будет проверен модератором, прежде чем станет видимым.