tijsverkoyen / css-to-inline-styles
CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.
Installs: 358 407 615
Dependents: 231
Suggesters: 4
Security: 0
Stars: 5 801
Watchers: 56
Forks: 187
Open Issues: 32
Requires
- php: ^5.5 || ^7.0 || ^8.0
- ext-dom: *
- ext-libxml: *
- symfony/css-selector: ^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^4.8.35 || ^5.7 || ^6.0 || ^7.5 || ^8.5.21 || ^9.5.10
README
About
CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.
Installation
The recommended installation way is through Composer.
$ composer require tijsverkoyen/css-to-inline-styles
Example
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles; // create instance $cssToInlineStyles = new CssToInlineStyles(); $html = file_get_contents(__DIR__ . '/examples/sumo/index.htm'); $css = file_get_contents(__DIR__ . '/examples/sumo/style.css'); // output echo $cssToInlineStyles->convert( $html, $css );
Known issues
- no support for pseudo selectors
- no support for css-escapes
- 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!)
Sites using this class
- Each site based on Fork CMS
- Print en Bind
- Tiki Wiki CMS Groupware (starting in Tiki 13)
- Laravel Framework