Short question : I've a $css variable containing CSS, I would like to find a given style (in my case the "body" one) in that variable and replace it with custom style.
Basic input output :
/* blablabla */
body {
background-color:#d0e4fe;
font-family: 'Afamily', sanas-serif;
}
span {
padding: 5px
}
h1 {
color:orange;
text-align:center;
}
body {
margin: 10px;
padding: 5px;
}
p {
font-family:"Times New Roman";
font-size:20px;
}
We call magicFunction():
echo magicFunction($css, 'font-color: pink; font-weight: bold;');
And we get :
/* blablabla */
body {
font-color: pink; font-weight: bold;
}
span {
padding: 5px
}
h1 {
color:orange;
text-align:center;
}
p {
font-family:"Times New Roman";
font-size:20px;
}
What's wrong ? Basically I'm stucked here
$bodyPattern = '/body\s\{[.|\s]*/m';
$found = preg_match_all($bodyPattern, $css, $matches);
It found only output stuff like :
"body {
'"
After the line return ... nothing.
Of course once I'll have the right regexp pattern I'll use preg_replace.
Why I want to do that : I want to apply CssToInlineStyle using my website CSS to build a newsletter, I'd like to change only the body style to avoid some style to be applied (like a background color). EDIT : This point is mentioned to let you know the "why", feel free to comment and give your view point on that, but please consider only the above question as what you're supposed to answer.