I have an ERP-System which stores text in RTF format and I'm trying to extract the plain text from it.
I've searched through Google and found a solutions like this one and some other ones which use REGEX replaces but none of them seem to work. I always get NULL or }}} or something completely wrong.
Here is the REGEX I tried:
$matches = array('/\{\\\\(.+?)\}/','/\\\\(.+?)\b/');
$row['text'] = preg_replace($matches,'',$row['text']);
However it returns: }}}
This is the RTF data I have:
{\rtf1\deff0{\fonttbl{\f0 Calibri;}{\f1 Arial;}}{\colortbl ;\red0\green0\blue255 ;}{\*\defchp \fs22}{\*\listoverridetable}{\stylesheet {\ql\fs22 Normal;}{\*\cs1\f1\fs20 Default Paragraph Font;}{\*\cs2\sbasedon1\f1\fs20 Line Number;}{\*\cs3\ul\fs22\cf1 Hyperlink;}{\*\ts4\tsrowd\fs22\ql\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Normal Table;}{\*\ts5\tsrowd\sbasedon4\fs22\ql\trbrdrt\brdrs\brdrw10\trbrdrl\brdrs\brdrw10\trbrdrb\brdrs\brdrw10\trbrdrr\brdrs\brdrw10\trbrdrh\brdrs\brdrw10\trbrdrv\brdrs\brdrw10\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Table Simple 1;}}\nouicompat\splytwnine\htmautsp\sectd\pard\plain\ql{\f1\fs20\cf0 Migration Fileserverdaten innerhalb derselben oder einer vertrauten Dom\u228\'e4ne}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Anpassung der Laufwerksfreigaben}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Freigabenerstellung wie Bestand (weitere Absprachen hierzu m\u246\'f6glich)}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Hostname(n) Quellsystem(e):}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Hostname Zielsystem:}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Bekanntes Datenvolumen:}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Clientseitige Nacharbeiten aufgrund fest vergebener Einstellungen}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 erfolgen nach Aufwand oder durch den Auftraggeber.}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Es wird im Besonderen darauf hingewiesen, da\u223\'df Datei- und Ornderberechtigungen 1:1 beibehalten werden. Die Neuvergabe jedweder Datei- oder Ordnerberechtigung kann nach Aufwand und Anweisung des Auftraggebers durchgef\u252\'fchrt werden.}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Voraussetzungen zur Zusatzaufwandsfreien Durchf\u252\'fchrung:}\f1\fs20\par\pard\plain\ql{\f1\fs20\cf0 Gigabit Switching zwischen allen Quell- und Zielsystemen, Vollzugriff auf den zu migrierenden Datenbestand}\f1\fs20\par\pard\plain\ql\f1\fs20\par}
Edit 2019: for all who find this question im using this single-class project since 4 years without a problem https://github.com/henck/rtf-html-php
I am posting a general solution to this issue for other guys jumped here.
public static function converToPlain($text){
$text = preg_replace('"{\*?\\\\.+(;})|\\s?\\\[A-Za-z0-9]+|\\s?{\\s?\\\[A-Za-z0-9‹]+\\s?|\\s?}\\s?"', '', $text);
return $text;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With