php class to inline css styles?

Emogrifier did not work for me, so I have developed this: https://github.com/djfm/cssin. I've tried several other libs and none worked on my HTML files, my lib is pretty OK I think.


You can try Premailer. The source is available on Github. (Just noticed your tag is PHP and Premailer is Ruby, so this might not count as a real answer for you...)


How's this?

https://www.myintervals.com/emogrifier.php

"... Emogrifier automagically transmogrifies your HTML by parsing your CSS and inserting your CSS definitions into tags within your HTML based on your CSS selectors. You can either use the form below to paste your HTML or CSS, or if you're more technically inclined, you can download the PHP source code and use it in your own applications. "


I was looking for the same thing tonight and I found this library https://github.com/christiaan/InlineStyle ,which does what I think you want.

It even understand selectors like ul > li and such.