首页 > 解决方案 > 如何通过 PHP 删除空的 CSS 属性?

问题描述

我有一个这样的字符串

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

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

我想像这样转换这个字符串

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

我怎样才能做到这一点?

标签: phpstringreplacestr-replace

解决方案


尝试:

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

虽然,输出也将包括,color:blue;而不仅仅是?background-color:red;.header


推荐阅读