我想删除给出错误的css规则,例如这里是示例
.banneritem {
border: 1px solid #CED4E0;
border color: #CBCBCB;// is not valid cause it actually refers to border-color missing (-)
margin-bottom: 10px;
}
是否有任何框架或库会从文件中省略这种 css 规则。
我在这里使用 sabberworm css 解析器我的示例代码
if ($loadedContents != ""){
preg_match_all('/display: none/is', $loadedContents, $matchvalue);
if (count($matchvalue[0]) > 0) {
$oCssParser = new Sabberworm\CSS\Parser($loadedContents);
$oDoc = $oCssParser -> parse();
foreach ($oDoc->getAllRuleSets() as $oRuleSet) {
if ($oRuleSet instanceof Sabberworm\CSS\RuleSet\AtRule) {
break;
}
$sSelector = $oRuleSet -> getSelectors();
$sSelector = $sSelector[0] -> getSelector();
$aDisplayRule = $oRuleSet -> getRules('display');
if (count($aDisplayRule) > 0) {
$aValues = $aDisplayRule['display'] -> getValues();
if ($aValues[0][0] == "none") {
$displayValue[] = "display:none;";
$displaySelector[] = $sSelector;
}
}
$bDisplayRule = $oRuleSet -> getRules('visibility');
if (count($bDisplayRule) > 0) {
$bValues = $bDisplayRule['visibility'] -> getValues();
if ($bValues[0][0] == "hidden") {
$visibilityValue[] = "visibility:hidden;";
$visibilitySelector[] = $sSelector;
}
}
}
}
}
我在这里处理所有 css 规则并同时找到 display:none 规则,由于这个错误的规则,我遇到了致命错误。
任何帮助将不胜感激。