php class to inline css styles?
Asked Answered
G

7

11

I was over at MailChimp's css inliner http://www.mailchimp.com/labs/inlinecss.php and I was wondering if there are any classes out there that can do this, I'd love to have it in my email code instead of going all the way over to MailChimp.

Basically I'm looking for the code, behind the page or something very similar.

Cheers.

Gondi answered 21/10, 2010 at 18:31 Comment(2)
So do you want a custom HTML parsing engine or do you want that page or what? Can you give a little more detail WHAT it is you want the supposed PHP class to do?Flocculate
Sorry about that, thought the post was pretty clear. The other dude picked it up OK. Shame it's ruby. I edited the post to be a little more specific.Gondi
L
3

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...)

Loeb answered 21/10, 2010 at 18:47 Comment(0)
S
9

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. "

Steinman answered 21/10, 2010 at 20:25 Comment(3)
Looks like it does not support css styles applied to tags eg h1 {color: red}, only classes.Haphazard
Actually demo on web site does not however downloadable code does. There's another issue though that it does not strip class attribute after creating inline style attribute.Haphazard
@alexeit: Actually I've since learnt that you can do this via the MailChimp API (apidocs.mailchimp.com/rtfm/inlinecss.func.php) after signing up for a free account. Plus it's able to strip the original CSS.Steinman
M
8

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.

Maquis answered 17/11, 2011 at 0:37 Comment(0)
L
3

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...)

Loeb answered 21/10, 2010 at 18:47 Comment(0)
B
2

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.

Began answered 28/10, 2013 at 19:42 Comment(0)
S
2

Pure PHP solution: https://github.com/tijsverkoyen/CssToInlineStyles (used by ).

tijsverkoyen/css-to-inline-styles if using .

Shoshanashoshanna answered 22/11, 2020 at 23:20 Comment(0)
C
1

The link in the OP appears to be gone, but MailChimp offers a style-to-inline convertor for free with no signup here:

http://beaker.mailchimp.com/inline-css

Still have to go "all thet way over to Mailchimp", though!

Conoid answered 8/1, 2013 at 18:4 Comment(0)
I
1

I was looking for the same thing (PHP based, downloadable, open source), but couldn't find it, so I created the following proxy/wrapper for the open source ruby library: https://github.com/onassar/PHP-Premailer

Hope it's helpful.

Ikeikebana answered 25/8, 2013 at 5:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.