Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
Improve minifier
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMadness committed Sep 2, 2016
1 parent 7e72c65 commit 3b30bce
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/StringHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ public static function str2url($str)
*/
public static function minify($str)
{
$matches = [];
preg_match_all('/<code>(.*?)<\/code>/mis', $str, $matches);
foreach ($matches[1] as $match) {
$matchesCode = $matchesPre = $matches = [];

preg_match_all('/<code.*?>(.*?)<\/code>/mis', $str, $matchesCode);
preg_match_all('/<pre.*?>(.*?)<\/pre>/mis', $str, $matchesPre);
$matches = array_merge($matchesCode[1], $matchesPre[1]);
foreach ($matches as $match) {
$str = str_replace($match, '$'.md5($match), $str);
}
$str = preg_replace(['/<!--(.*)-->/Uis', "/[[:blank:]]+/"], ['', ' '],
str_replace(["\n", "\r", "\t"], '', $str));
foreach ($matches[1] as $match) {
foreach ($matches as $match) {
$str = str_replace('$'.md5($match), $match, $str);
}
return $str;
Expand Down

0 comments on commit 3b30bce

Please sign in to comment.