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

时间:2018-08-14 18:15:50

标签: php regex

这是我的字符串,我要删除具有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 个答案:

答案 0 :(得分:2)

使用以下正则表达式:

map

经过测试的here