代码之家  ›  专栏  ›  技术社区  ›  hretic

从字符串中删除特定样式标记的regext

  •  0
  • hretic  · 技术社区  · 7 年前

    这是我的字符串,我想用 yasrcss-inline-css ID及其内容

    $text = "abc
    <style id='yasrcss-inline-css' type='text/css'>
    
            .rateit .rateit-range {
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/star.png) left 0px !important;
            }
    
            .rateit .rateit-hover {
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/star.png) left -21px !important;
            }
    
            .rateit .rateit-selected {
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/star.png) left -42px !important;
            }
    
            div.medium .rateit-range {
                /*White*/
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/stars24.png) left 0px !important;
            }
    
            div.medium .rateit-hover {
                /*Red*/
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/stars24.png) left -29px !important;
            }
    
            div.medium .rateit-selected {
                /*Yellow*/
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/stars24.png) left -58px !important;
            }
    
            /* Creating set 32 */
    
            div.bigstars .rateit-range {
                /*White*/
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/stars32.png) left 0px !important;
            }
    
            div.bigstars .rateit-hover{
                /*red*/
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/stars32.png) left -37px !important;
            }
    
            div.bigstars .rateit-selected
            {
                /*Gold*/
                background: url(https://www.newseo.ir/wp-content/plugins/yet-another-stars-rating/img/stars32.png) left -74px !important;
            }
    
    
    </style>
    ";
    

    这里是我的正则表达式

    echo preg_replace("/<style id='yasrcss-inline-css' type='text\/css'>(.*?)<\/style>/", " ", $text);
    

    但它不起作用,我是不是错过了什么?

    1 回复  |  直到 7 年前
        1
  •  2
  •   No Name    7 年前

    使用以下regex:

    (<style id='yasrcss-inline-css') (.|\n)*?(</style>)
    

    测试 here