<?php
$css=<<<CSS
p.special {
font: 12pt/14pt sans-serif;
margin: 5px 0px 2px 25px;
border: medium dashed #ff0000;
background: white url( http://www.foo.com/image.gif ) repeat-x fixed top right; }
/*************************************************
Save with a name ending in .css such as styles.css *************************************************/
h1 {
color: red; padding: 10px; text-decoration: underline;
}
.code_sample ul {
list-style-type: upper-roman; /* LEAVE THIS BIT OUT */
margin-left: 50px;
}
.code_sample p {
color: darkblue
}
a:link, a:visited, a:hover, a:active {
background-color: green;
color: white;
padding: 10px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
CSS;
$patterns=[
'~\s+~', // reduce one or more consecutive whitespace characters ([\n\r \t]+) to a single space ...this combines the 2nd, 3rd, and 4th pattern from catchamonkey's answer
'~/\s*\*.*?\*/\s*|(?:(?<=[,:;{}(]) | (?=[,:;{})]))|;(?=})|^ | $~s' // comment blocks, leading/trailing spaces after ,:;{} characters, space before ), space after (, semicolon followed by }, whitespace at start/end of file
];
$replacements=[
' ',
''
];
// And here's a rabbit hole: https://regex101.com/r/nZbHND/1
var_export(preg_replace($patterns,$replacements,$css));
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
'p.special{font:12pt/14pt sans-serif;margin:5px 0px 2px 25px;border:medium dashed #ff0000;background:white url(http://www.foo.com/image.gif) repeat-x fixed top right;}h1{color:red;padding:10px;text-decoration:underline;}.code_sample ul{list-style-type:upper-roman;margin-left:50px;}.code_sample p{color:darkblue}a:link,a:visited,a:hover,a:active{background-color:green;color:white;padding:10px 25px;text-align:center;text-decoration:none;display:inline-block;}'