Skip to content
Advertisement

How to remove empty CSS property by PHP?

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?

Advertisement

Answer

Try:

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

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement