php分析并保留必要的css信息?
求效率最快的方法。代码:<?php$arr=array(
".hd",
".ft",
".bd",
".br"
);
$class_str=<<<STR
.mod{margin:5px;}
.hd,.bd,.ft{overflow:hidden;_overflow:visible; _zoom:1;}
.inner{position:relative;}
b{display:block;background-repeat:no-repeat;font-size:1%;position:relative;z-index:10;}
.tl, .tr, .bl, .br{height:10px; width:10px;float:left;}
.tl{background-position: left top;}
.tr{background-position: right top;}
.bl{background-position: left bottom;} 
.br{background-position: right bottom;}
.br,.tr{float:right;}
STR;?>

解决方案 »

  1.   

    很简单:
    $rst = array();
    $x = split("\n",$class_str);foreach($x as $line){
        foreach($arr as $search){
            if(preg_match("/\{$search}/",$line)){
                $rst[]=$line;
                break;    
            }
        }
    }print_r($rst);
    代码未经测试~自己测下!
      

  2.   


    $arr=array(
        "hd",
        "ft",
        "bd",
        "br"
    );
    $class_str=<<<STR
        .mod{margin:5px;}
        .hd,.bd,.ft{overflow:hidden;_overflow:visible; _zoom:1;}
        .inner{position:relative;}
        b{display:block;background-repeat:no-repeat;font-size:1%;position:relative;z-index:10;}
        .tl, .tr, .bl, .br{height:10px; width:10px;float:left;}
        .tl{background-position: left top;}
        .tr{background-position: right top;}
        .bl{background-position: left bottom;} 
        .br{background-position: right bottom;}
        .br,.tr{float:right;}    
    STR;
    $arr = implode('|',$arr);
    preg_match_all("/\.($arr).*\}/i", $class_str, $out);
    print_r($out[0]);