I have HTML code like:
-
This works for me and it's easy to add/remove special cases. Works with CSS, HTML and JS.
function inline_trim($t)
{
$t = preg_replace('/>\s*\n\s*', '><', $t); // line break between tags
$t = preg_replace('/\n/', ' ', $t); // line break to space
$t = preg_replace('/(.)\s+(.)/', '$1 $2', $t); // spaces between letters
$t = preg_replace("/;\s*(.)/", ';$1', $t); // colon and letter
$t = preg_replace("/>\s*(.)/", '>$1', $t); // tag and letter
$t = preg_replace("/(.)\s*", '$1<', $t); // letter and tag
$t = preg_replace("/;\s*", '<', $t); // colon and tag
$t = preg_replace("/;\s*}/", '}', $t); // colon and curly brace
$t = preg_replace("/(.)\s*}/", '$1}', $t); // letter and curly brace
$t = preg_replace("/(.)\s*{/", '$1{', $t); // letter and curly brace
$t = preg_replace("/{\s*{/", '{{', $t); // curly brace and curly brace
$t = preg_replace("/}\s*}/", '}}', $t); // curly brace and curly brace
$t = preg_replace("/{\s*([\w|.|\$])/", '{$1', $t); // curly brace and letter
$t = preg_replace("/}\s*([\w|.|\$])/", '}$1', $t); // curly brace and letter
$t = preg_replace("/\+\s+\'/", "+ '", $t); // plus and quote
$t = preg_replace('/\+\s+\"/', '+ "', $t); // plus and double quote
$t = preg_replace("/\'\s+\+/", "' +", $t); // quote and plus
$t = preg_replace('/\"\s+\+/', '" +', $t); // double quote and plus
return $t;
}
- 热议问题