0
我有以下的CSS代码PHP正则表达式的preg_match得到CSS类,id和标签
thead
{
/*some code*/
}
tr,img {
/*some code*/
}
@page {
/*some code*/
}
p,h2,h3 {
/*some code*/
}
h2,h3 {
/*some code*/
}
img {
/*some code*/
}
我想与使用PHP正则表达式的preg_match或preg_replace函数图片IMG CSS。 例如,如果我寻找IMG,以下输出将必须表明
tr,img {
/*some code*/
}
img {
/*some code*/
}
PHP代码是
$str='img{ } .class_class { } #awesome_id{ }';
$search='img';
$str = preg_replace("~{(."$search".)}~s","", $str);
$arr = array_filter(explode(' ',$str));
print_r($arr);
你能否提供你已经在问题中做出的尝试? –
我加了php代码。 –
如果没有[嵌套{}](http://programmers.stackexchange.com/a/23241/126902),请使用[preg_match_all]尝试[像这样](https://regex101.com/r/rK1xJ5/1) ](http://php.net/manual/en/function.preg-match-all.php)函数。 –