I want to change every css rule in a string whitch I extracted from a HTML email body.
The string contains css inside a element whitch influence my website styling.
I want to add an element (div class) to every css rule inside that string.
Is this possible with php?
Example:
$string = '<style type="text/css">body { blah blah } .div1 { blah blah } .div2 { blah blah }</style> Blah blah blah body text blah blah';
$extractcss = strip_tags($string , '<style>');
I want to add .mydiv to every css rule to get this:
$extractcss = '.mydiv body { blah blah } .mydiv .div1 { blah blah } .mydiv .div2 { blah blah }';
With the new string I want to influence the styling of the email body so that it no longer has any effect on my website styling.
Thanks in advance!
2
Answers
With te help of this topic I have the solution for my problem.
With the following function I parse the CSS from a string. After that I make a new css string with a div class in front of every css rule.
The code have some error, anyway the simpliest way is to use the str_replace() php function