سؤال

I am looking for a way to get a CSS selector in PHP. So say I have a string in PHP like

#something
{
   background-color: #fff;
   float: right;
}

// Some Comment with } and #
#some #some2 div#some3 .someClass
{
   float: left;
   color: #000;
}

Now I would like to be able to get all CSS selectors which have the property float. In this case I would like to get #some #some2 div#some3 .someClass as well as #something

Working with regular expressions however seems to be not possible since there is now way to tell exactly when a selector finishes. Do you have any idea how I could achieve this?

هل كانت مفيدة؟

المحلول

There's a library that parses CSS and gives you object oriented method to traverse throughout CSS file: https://github.com/sabberworm/PHP-CSS-Parser

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top