I am working to clean up CSS output with str_replace, but need to ignore certain block of strings with a defined start and end.
Ignore anything that starts with:
@media blah(this can be any value) {
content to ignore:
.class {
property: value;
}
and ends with:
}/*ends*/
And do str_replace outside that block instead:
.otherclass {property:value;}
PHP:
$output = str_replace("{", "{\n", $output);
$output = str_replace("}", "}\n", $output);
The reason is that @media block need proper indentation which is already correctly formatted, and should not be touched by str_replace which simple return readable lines:
.otherclass {
property:value;
}
How would you say it in PHP?
Thanks
Regex won’t work since lookbehind doesn’t allow variable length. Try and loop through the file.