Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8114107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:03:08+00:00 2026-06-06T03:03:08+00:00

I use this class to parse a .css file. https://github.com/sabberworm/PHP-CSS-Parser I thought it’s easy

  • 0

I use this class to parse a .css file.
https://github.com/sabberworm/PHP-CSS-Parser
I thought it’s easy but this class is complicated and I’m completly green in object oriented programing, so I have a problem.

(…) including all class files etc.

$oParser = new CSSParser(file_get_contents('files/sample.css'));
$oDoc = $oParser->parse();
$selectors=$oDoc->getAllRuleSets();
$nazwy=$oDoc->getContents();

foreach($selectors as $selektor=> $val)
    {       
    $w=$val->getSelectors();            
    echo "<h3>$selektor</h3>";
    $tmp=$val->getRules();

        foreach($tmp as $nazwa => $attrib)
        {
        $wartosc= $attrib->getValue();
        echo "<br>$nazwa:$wartosc;";            
        }               
    }

this code will output something like this

<h1>0</h1>
color:red;
margin:10px;


<h1>1</h1>
color:green;
margin:20px;

it’s almost ok but I want selectors names (eg div #someid) instead of index of current css block.Have any idea how to get those?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:03:10+00:00Added an answer on June 6, 2026 at 3:03 am

    Use echo "<h3>".implode(', ' $w)."</h3>".

    The reason is as follows: $val represents a declaration block which is a rule set with several comma-separated selectors (The key $selektor only contains the index of the declaration block which is completely arbitrary for most usages). To get the selectors, use $val->getSelectors() (which you did). This will get you an array of all selectors.

    The declaration block:

    h1, h2 { value: 1; }
    

    will thus be parsed into a CSSDeclarationBlock object with the selector array [‘h1’, ‘h2’]. To get back the selectors as they were originally defined, use implode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this library: https://github.com/robbiehanson/CocoaAsyncSocket My test code: #import <UIKit/UIKit.h> @class GCDAsyncUdpSocket; @interface ThirdViewController
I'm trying to to use this class http://robbyonrails.com/articles/2005/05/11/parsing-a-rss-feed but am not sure where to
I don't have any idea how to use this class in .net. Anyone wants
I have an issue regarding Sendkeys Class, as i want to use this class
I like the convenience of unbounded_buffer, but I also want to use this class
I use this pseudo-class to make Ajax request to server: function RequestManager(url, params, success,
Is it possible to change PowerPacks.LineShape smoothingMode? I tried to use this code(a class
I'm trying to use: // this is a BreakHistory class from the ADO.NET Data
I imagine to use XML serialization like this: class Foo { public Foo (string
I have a css class pause . This is applied in various pages. Only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.