This question already has an answer here:
How do I safe match all <style>
blocks in body using preg_match_all()?
Google is not my friend today.
$haystack = '<body>
<style>
.class {
foo: bar;
}
</style>
<p>Hello World</p>
<style>
/* A comment for <p> */
.class > p {
this: that;
}
</style>
<p>Some HTML</p>
</body>';
preg_match_all('#<style>([^<]+)#is', $haystack, $matches, PREG_SET_ORDER);
var_dump($matches);
preg_match_all('#<style>(.*)</style>#is', $haystack, $matches, PREG_SET_ORDER);
var_dump($matches);
Did not work, as it matched the < in the style comment.
</div>