CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very usefull when you're sending emails.
PHP CssToInlineStyles is a class to convert HTML into HTML with inline styles.
The recommended installation way is through Composer.
$ composer require tijsverkoyen/css-to-inline-styles
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
// Convert HTML + CSS to HTML with inlined CSS
$cssToInlineStyles= new CssToInlineStyles();
$cssToInlineStyles->setHTML($html);
$cssToInlineStyles->setCSS($css);
$html = $cssToInlineStyles->convert();
// Or use inline-styles blocks from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$cssToInlineStyles->setUseInlineStylesBlock(true);
$html = $cssToInlineStyles->convert();
// Or use linked files from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$cssToInlineStyles->setLoadCSSFromHTML(true);
$html = $cssToInlineStyles->convert();
The following properties exists and have get/set methods available:
Property | Default | Description |
---|---|---|
cleanup | false | Should the generated HTML be cleaned? |
useInlineStylesBlock | false | Use inline-styles block as CSS. |
stripOriginalStyleTags | false | Strip original style tags. |
excludeMediaQueries | true | Exclude the media queries from the inlined styles. |
- no support for pseudo selectors
- UTF-8 charset is not always detected correctly. Make sure you set the charset to UTF-8 using the following meta-tag in the head:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
. (Note: using<meta charset="UTF-8">
does NOT work!)
- Each site based on Fork CMS
- Print en Bind
- Tiki Wiki CMS Groupware (starting in Tiki 13)