Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
RTF to HTML converter in PHP
Rtf Html Php is a PHP library that converts RTF documents to HTML using a pure-PHP parser, installed with Composer as henck/rtf-to-html.
Rtf Html Php is a pure PHP library that parses RTF (Rich Text Format) documents and converts them to HTML output. It reads an RTF string or file and produces an HTML representation through a HtmlFormatter class, running on any PHP installation with the mbstring extension enabled. The library was written by developer Henck (based on the Composer vendor name "henck") after existing RTF-to-HTML solutions failed to work or required external executables.
mb_convert_encoding for character handling.composer require henck/rtf-to-html, then use namespaces RtfHtmlPhp\Document and RtfHtmlPhp\Html\HtmlFormatter.HTML-ENTITIES, and you can pass any encoding supported by mb_list_encodings() (for example UTF-8) to the HtmlFormatter constructor.Document object prints the parser's parse tree, which helps developers inspect how the RTF was read.Document constructor throws an exception if the RTF cannot be parsed; parse errors also generate PHP notices.new Document($rtf) and format it with HtmlFormatter to get HTML output..rtf file with file_get_contents() and feed the content to Document, then echo the formatted HTML.HtmlFormatter('UTF-8') to receive UTF-8 HTML instead of the default HTML entities, matching your site's charset.The library works in two steps: first, Document parses the RTF input into a parse tree; second, HtmlFormatter walks that tree and returns HTML. If the RTF is invalid, Document throws an exception. The conversion relies on PHP's mb_convert_encoding to handle Unicode RTF characters.
php-mbstring module; without it the converter will not work.Yes, it depends on the mbstring extension because it uses mb_convert_encoding for character conversion. Most fresh PHP installations include this module, but you should verify your environment before using the library.
Run composer require henck/rtf-to-html in your project directory. After that, you can use the RtfHtmlPhp\Document and RtfHtmlPhp\Html\HtmlFormatter classes in your code.
Yes. Pass 'UTF-8' (or any encoding returned by mb_list_encodings()) to the HtmlFormatter constructor. The default output encoding is HTML-ENTITIES.
The Document constructor throws an exception if the RTF cannot be parsed. During parsing, issues with specific control words may also generate PHP notices, which you can inspect for debugging.
