Get CSS style from PHP

I am analyzing pages using Simple DOM parser. It is neat, but I would like to get an applied CSS style for each element. Not only inline styles, but every style that applies to this element, being inline, inline, or external.

Is there a class that does this? If not, how would you do it? I don’t care that you don’t use styles, cascades or browser styles. All applied styles would be enough.

+3
source share
3 answers

According to Martin, while you are almost writing a browser in PHP - this is a big question! As with any major project, the key is to break it down into more manageable steps (although some of them are not entirely straightforward).

You will need:

  • work out which (if any) external css files are associated with
  • (for Gumbo echo): find (or develop) a way to read and interpret external css, in-page css and inline css
  • determine which styles apply to each element (including the styles applied by .class, #id and the element type) and the parents of each element, including rules that css override, which other CSS rules, etc.

, , , MPDF, ( ), , .

+3

. :

<style>
   p .foo {
     color: yellow;
   }
   span > *[href] {
     color: red;
   }
   img + .foo {
     color: green;
   }
   span #bar {
     color: blue;
   }
   .baz #bar {
     color: black;
   }
</style>      
<p class="baz">Lorem ipsum <span>dolor sit 
  <img src="x.png"><a id="bar" class="foo" href="#top">amet</a>,</span>
  consectetur adipiscing elit.
</p>

? 5 . CSS2.1, 3 .

Gumbo, CSS . PHP, .

( CSS, - . , " , CSS" - , PHP-)

- - (, Gecko Webkit) CSS. , , PHP.

+1

CSS QUAIL - , psuedo- DOMDocument. - Xpaths DOMDocument node , , 70% W3C.

0
source

Source: https://habr.com/ru/post/1717239/


All Articles