2

I am looking for an implementation of a CSS generator in PHP. The idea is that the script gets some input like : array('element' => 'div', 'color' => '#00ff00') and generates a file with :

div {
  color : #00ff00; 
} 

Or something similar, you get the idea. Please do not point to some software or online service, I am looking for an actual open source implementation that I can possibly use in my projects, like a PHP class or so.

Is there an open source implementation of that which you know of ?

9
  • 2
    It seems pretty easy to write one yourself, but who knows. Commented Sep 7, 2012 at 0:43
  • 1
    I could write one easily indeed, but I thought there is no need to reinvent the wheel if there is something out there. Commented Sep 7, 2012 at 0:44
  • 3
    the wheel is not very complicated in this case, reinvent it Commented Sep 7, 2012 at 0:46
  • well, there is a javascript solution called www.lesscss.org, hope it helps Commented Sep 7, 2012 at 0:46
  • hmm, i really don't see why all the negative votes, i guess people don't like the question. Anyway, I respect that. Commented Sep 7, 2012 at 0:48

1 Answer 1

2

LESS or SASS...both free, open source. They will provide at least a good starting point for CSS parsing and templating logic (even if it may not be the right solution-see comments).

  • LESS - JavaScript, C#, PHP versions exist (maybe others).
  • SASS - Ruby, JavaScript, and PHP

Unlike some of the comments state, this isn't a trivial task if you want the tool to be useful (I'm assuming your code example is simplified from a full implementation).

There are a couple of ways to implement CSS pre-processing:

  • In the browser (the JS versions). This puts a lot of load on the browser with every page view and can cause issues.

  • On the server. This approach usually generates then caches the output, so it's acceptably fast. I like this for development work because I can see my changes in real time.

  • Pre-compilation. With this approach, you generate the final CSS independently of the web server and statically link to it. This is the highest performance approach, but requires the most manual work.

Sign up to request clarification or add additional context in comments.

7 Comments

They both seem pretty nice solutions, I will definitely check them. Do you think any of them is superior in terms of integrating with simple PHP projects ?
I only have experience with LESS in c#; my experience base been very positive in that regard. I just added a link to a PHP port of LESS.
LessPHP seems pretty interesting, I will take a closer look now thanx ! leafo.net/lessphp
If you search this site for LESS or SASS you should find a variety of info. Both are very popular.
Just to clarify, I +1 your answer. In my case, i will need to create sort of a panel that gets user defined values, produces a new CSS file and includes it in the page. I'm not particularly sure if LESS/SASS are a bit overkill for that, but I will definitely investigate.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.