If you really need to use simplehtmldom to extract this :
For
<style>
...
</style>
Use :
$css = $html->find('style')->innertext;
For
<div style="background:blue; color:white;"></div>
Use :
$css = $html->find('div[style]')->style;
If there's more than one div with style atribute or more than one <style>, you can use a foreach to loop between them.
To parse styles :
in PHP :
$s = 'background:blue; color:white;';
$results = [];
$styles = explode(';', $s);
foreach ($styles as $style) {
$properties = explode(':', $style);
if (2 === count($properties)) {
$results[trim($properties[0])] = trim($properties[1]);
}
}
var_dump($results);
in JS
let s = 'background:blue; color:white;';
let results = {};
let styles = s.split(";");
for (let style in styles) {
let properties = styles[style].split(":");
if (properties.length === 2) {
results[properties[0].trim()] = properties[1].trim();
}
}
console.log(results);
https://jsfiddle.net/zyfhtwj2/
styleelements) or inline styles (insidestyleattribute on elements).styletag, or the value of thestyleattribute. So you should be able to get those values using an HTML parser.