0

here is my string , i want to remove the style tag with yasrcss-inline-css id and its content

$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>
";

here my regex

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

but it doesn't work , am i missing something ?

1
  • you may need to use the /m modifier on your regex. Commented Aug 14, 2018 at 18:19

1 Answer 1

2

Use the following regex:

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

Tested here

Sign up to request clarification or add additional context in comments.

4 Comments

i did much the same, but i used ([\s\S]*?) realistically as long as it works.
thanx , any idea why this wont work ? $text = "<style type='text/css'> a </style>"; echo preg_replace("/(<style type='text\/css') (.|\n)*(<\/style>)/", " ", $text);
@hretic you're missing the > after 'text\/css' ;)
thanx , i didnt put > bcuz you didnt put it on your answer and that regex worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.