Parsing CSS with PHP

Discussion in 'PHP' started by ryan_uk, Jul 15, 2013.

  1. #1
    I've had a look around and seen a few PHP CSS parsers, but so far they just seem to be for parsing an individual file.

    What I am wanting to do is read in all of the CSS for a document (from individual files and specified within the HTML - I'm not concerned about JavaScript for now) and check the values of the final overriding CSS.

    Has anyone ever come across something quite like this? Before I dive into coding something myself for it, I thought I would check.
     
    Solved! View solution.
    ryan_uk, Jul 15, 2013 IP
  2. scriptjerk

    scriptjerk Active Member

    Messages:
    43
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    58
    #2
    Let me get this right, you want to check the actual css elements values for each rule to compare with something?
     
    scriptjerk, Jul 15, 2013 IP
  3. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #3
    So the process would be:


    Read the HTML file -> read in CSS (from files and within the document) -> check a particular HTML tag for an ID/class(es) -> grab the CSS elements and their values and compare them (only the "predominent" ones, not any that have been overriden) against something (like if background-color is set to #00000).

    I've seen some PHP scripts for helping to parse CSS, but so far just for individual files. I'm looking to do it on a bigger scope, so if there's nothing pre-existing I'll just write it myself.
     
    ryan_uk, Jul 15, 2013 IP
  4. #4
    Id probably just write my own, i dont think you will find anything.
     
    scriptjerk, Jul 15, 2013 IP
  5. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #5
    Yeah, the conclusion I'm coming to after searching a lot. A fun little challenge for while I'm on night shift. :) I wonder if a parser for multiple files (including CSS within the HTML) would be useful for anyone else.
     
    ryan_uk, Jul 15, 2013 IP
  6. scriptjerk

    scriptjerk Active Member

    Messages:
    43
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    58
    #6
    Possibly. If you need some coding help, let me know, i have spare time over the next few days.
     
    scriptjerk, Jul 15, 2013 IP
    ryan_uk likes this.