How to remove empty CSS property by PHP?

Tags: , , ,



I have a string like this

.header{
font-family:;
background-color:red;
color:blue;
line-height:;
}

.footer{
background-color:green;
color:;
}

I want to convert this string-like this

.header{
background-color:red;
color:blue;
}
.footer{
background-color:green;
}

How can I achieve this?

Answer

Try:

preg_replace('/.*:s*;/i', '', $string);

although, the output would include color:blue; too and not just background-color:red; for .header?



Source: stackoverflow