<style type="text/css">
*{
margin:0;
padding:0;
}
body{
font-size:13px;
}
#nav{
margin:100px;
}
#nav li{
float:left;
list-style:none;
}
#nav li a{
padding:10px 20px;
display:block;
color:#000;
font-size:14px;
font-family:"微软雅黑";
}这段CSS代码,求正则匹配![/code]

解决方案 »

  1.   

    <style type="text/css">
    内容
    </style>
      

  2.   

    说说你期望的结果不然我的单纯理解只是 /<style type=\"text\/css\">(.*)<\/style>/is而已
      

  3.   


    $str =<<<eof
    <style type="text/css">
    *{
        margin:0;
        padding:0;
    }
    body{
        font-size:13px;
    }
    #nav{
        margin:100px;
    }
    #nav li{
        float:left;
        list-style:none;
    }
    #nav li a{
        padding:10px 20px;
        display:block;
        color:#000;
        font-size:14px;
        font-family:"微软雅黑";
    }
    </style>
    eof;
    if(preg_match('/<style\s+type="text\/css">(.*?)<\/style>/is',$str,$arr)){
      echo '<pre />';
      print_r($arr);
    }
      

  4.   

    <?php
    header("Content-type:text/html;charset=gb2312"); 
    $str = <<<html
    <html>
    <head>
    <style type="text/css">
    *{
        margin:0;
        padding:0;
    }
    body{
        font-size:13px;
    }
    #nav{
        margin:100px;
    }
    #nav li{
        float:left;
        list-style:none;
    }
    #nav li a{
        padding:10px 20px;
        display:block;
        color:#000;
        font-size:14px;
        font-family:"微软雅黑";
    }
    </style>
    <title>这是标题~....</title>
    </head>
    <body>
    <ul id="nav">
    <li><a href="http://www.baidu.com">百度</a></li>
    <li><a href="http://www.baidu.com">谷歌</a></li>
    <li><a href="http://www.yahu.com">雅虎</a></li>
    <li><a href="http://www.biing.com">必应</a></li>
    </ul>
    </body>
    </html>
    html;
    $reg1="/<style[^>]*>(.*?)<\/style>/is";
    if(preg_match_all($reg1,$str,$arr))
    {
    echo "CSS部分:<br/>".$arr[1][0]."<br/>";
    }
    $reg2="/<li>(.*?)<\/li>/i";
    if(preg_match_all($reg2,$str,$arr))
    {
    foreach($arr[1] as $a)
    {
    echo "LI内容为:<br/><xmp>".$a."</xmp><br/>";
    }
    }
    ?>