All Projects → henck → rtf-html-php

henck / rtf-html-php

Licence: GPL-2.0 license
RTF to HTML converter in PHP

Programming Languages

PHP
23972 projects - #3 most used programming language
Rich Text Format
576 projects

Projects that are alternatives of or similar to rtf-html-php

color-converter
Command line tool for converting colors from RGB to HEX and vice versa.
Stars: ✭ 17 (-80.68%)
Mutual labels:  converter
Video-to-audio-converter
A simple tool to convert video files into mp3 audio files
Stars: ✭ 40 (-54.55%)
Mutual labels:  converter
tyson
A TypeScript serialization/deserialization library to convert objects to/from JSON
Stars: ✭ 25 (-71.59%)
Mutual labels:  converter
ipynb-py-convert
Convert .py files runnable in VSCode or Atom/Hydrogen to Jupyter .ipynb notebooks and vice versa
Stars: ✭ 38 (-56.82%)
Mutual labels:  converter
ubase
remove accents from utf8 strings
Stars: ✭ 14 (-84.09%)
Mutual labels:  converter
highlight
Source code to formatted text converter
Stars: ✭ 44 (-50%)
Mutual labels:  rtf
ical2json
A simple node package to convert ical data to json
Stars: ✭ 46 (-47.73%)
Mutual labels:  converter
svg2ass
Svg2ass - convert SVG vector graphics to ASS subtitle draw instructions.
Stars: ✭ 22 (-75%)
Mutual labels:  converter
Text to MD
Convert your docs to markdown format.
Stars: ✭ 15 (-82.95%)
Mutual labels:  converter
unicode-formatter
Convert portions of text to fancy text using unicode fonts for use on Twitter and other sites that don't support rich text
Stars: ✭ 31 (-64.77%)
Mutual labels:  converter
form-data-json
A zero dependency, cross browser library to easily get or set/manipulate form input values as/from a json object.
Stars: ✭ 37 (-57.95%)
Mutual labels:  converter
react-in-out-textarea
A simple React.js User Interface Component that is like Google Translate with full TypeScript Support
Stars: ✭ 28 (-68.18%)
Mutual labels:  converter
can2mqtt
Bidirectional CAN-Bus to MQTT-Bridge
Stars: ✭ 39 (-55.68%)
Mutual labels:  converter
rtfraptor
Extract OLEv1 objects from RTF files by instrumenting Word
Stars: ✭ 50 (-43.18%)
Mutual labels:  rtf
Create-EXEFromPS1
Takes one PowerShell script and any number of supplementary files or even a directory and creates an exe using Windows's built in iexpress program. The exe will run on any machine with PowerShell 2.0+.
Stars: ✭ 81 (-7.95%)
Mutual labels:  converter
video2gif
A batch script for convert video to GIF files by FFmpeg.exe on Windows
Stars: ✭ 48 (-45.45%)
Mutual labels:  converter
svg2polylines
Rust library to convert SVG data to a list of flattened polylines. Also includes FFI bindings.
Stars: ✭ 16 (-81.82%)
Mutual labels:  converter
LC2KiCad
A C++ utility that converts EasyEDA (LCEDA) file to KiCad 5 Documents.
Stars: ✭ 103 (+17.05%)
Mutual labels:  converter
o2d3m
Wavefront OBJ to Doom3 map converter.
Stars: ✭ 15 (-82.95%)
Mutual labels:  converter
express-to-koa
Use express middlewares in Koa2, the one that really works.
Stars: ✭ 18 (-79.55%)
Mutual labels:  converter

rtf-html-php

An RTF to HTML converter in PHP

In a recent project, I desperately needed an RTF to HTML converter written in PHP. Googling around turned up some matches, but I could not get them to work properly. Also, one of them called passthru() to use a RTF2HTML executable, which is something I didn’t want. I was looking for an RTF to HTML converter written purely in PHP.

Since I couldn’t find anything ready-made, I sat down and coded one up myself. It’s short, and it works, implementing the subset of RTF tags that you’ll need in HTML and ignoring the rest. As it turns out, the RTF format isn’t that complicated when you really look at it, but it isn’t something you code a parser for in 15 minutes either.

How to use it

Install this package using composer. Then do this:

use RtfHtmlPhp\Document;

$rtf = file_get_contents("test.rtf"); 
$document = new Document($rtf); // or use a string directly

Document will raise an exception if the RTF document could not be parsed. Parse errors will generate PHP notices.

If you’d like to see what the parser read (for debug purposes), then call this:

echo $document;

To convert the parser’s parse tree to HTML, call this (but only if the RTF was successfully parsed):

use RtfHtmlPhp\Html\HtmlFormatter;
$formatter = new HtmlFormatter();
echo $formatter->Format($document);

For enhanced compatibility the default character encoding of the converted RTF unicode characters is set to HTML-ENTITIES. To change the default encoding, you can initialize the Html object with the desired encoding supported by mb_list_encodings(): ex. UTF-8

$formatter = new HtmlFormatter('UTF-8');

Install via Composer

composer require henck/rtf-to-html

Caveats

  • Please note that rtf-html-php requires your PHP installation to support the mb_convert_encoding function. Therefore you must have the php-mbstring module installed. For fresh PHP installations, it will usually be there.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].