Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
[PHP] HTML Minifier
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="oxcakmak" data-source="post: 468578" data-attributes="member: 100586"><p>Simply add the code in the minify.php file to the top of the config file:</p><p>[CODE]<?php</p><p>/*</p><p>* Special thanks: Stephen Clay <steve@mrclay.org></p><p>*/</p><p>function sanitize_output($html){</p><p> $html = preg_replace_callback(</p><p> '/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'</p><p> ,''</p><p> ,$html);</p><p> </p><p> $html = preg_replace_callback(</p><p> '/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/i'</p><p> ,''</p><p> ,$html);</p><p> </p><p> $html = preg_replace_callback(</p><p> '/<!--([\\s\\S]*?)-->/'</p><p> ,''</p><p> ,$html);</p><p> </p><p> $html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'</p><p> ,''</p><p> ,$html);</p><p> </p><p> $html = preg_replace_callback(</p><p> '/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'</p><p> ,''</p><p> ,$html);</p><p> </p><p> // @todo take into account attribute values that span multiple lines.</p><p> $html = preg_replace('/^\\s+|\\s+$/m', '', $html);</p><p> </p><p> $html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body'</p><p> .'|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'</p><p> .'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'</p><p> .'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'</p><p> .'|ul)\\b[^>]*>)/i', '$1', $html);</p><p> </p><p> $html = preg_replace(</p><p> '/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</'</p><p> ,'>$1$2$3<'</p><p> ,$html);</p><p> </p><p> $html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $html);</p><p> return $html;</p><p>}</p><p>ob_start("sanitize_output");</p><p>?>[/CODE]</p><p></p><p>[URL unfurl="true"]https://github.com/oxcakmak/PHP-HTML-CSS-JS-Minifier[/URL]</p></blockquote><p></p>
[QUOTE="oxcakmak, post: 468578, member: 100586"] Simply add the code in the minify.php file to the top of the config file: [CODE]<?php /* * Special thanks: Stephen Clay <steve@mrclay.org> */ function sanitize_output($html){ $html = preg_replace_callback( '/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i' ,'' ,$html); $html = preg_replace_callback( '/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/i' ,'' ,$html); $html = preg_replace_callback( '/<!--([\\s\\S]*?)-->/' ,'' ,$html); $html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i' ,'' ,$html); $html = preg_replace_callback( '/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i' ,'' ,$html); // @todo take into account attribute values that span multiple lines. $html = preg_replace('/^\\s+|\\s+$/m', '', $html); $html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body' .'|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|form' .'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta' .'|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)' .'|ul)\\b[^>]*>)/i', '$1', $html); $html = preg_replace( '/>(\\s(?:\\s*))?([^<]+)(\\s(?:\s*))?</' ,'>$1$2$3<' ,$html); $html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $html); return $html; } ob_start("sanitize_output"); ?>[/CODE] [URL unfurl="true"]https://github.com/oxcakmak/PHP-HTML-CSS-JS-Minifier[/URL] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
[PHP] HTML Minifier
Top