silvermine / php-rtflex
此包已被 弃用 并不再维护。未建议任何替代包。
关于此包最新版本(dev-master)没有可用的许可信息。
dev-master
2018-12-17 19:45 UTC
This package is not auto-updated.
Last update: 2020-02-21 16:02:40 UTC
README
此项目不再受支持或维护。请考虑使用其他项目进行新开发。
RTFLex
RTFLex 是一个简单的 RTF 格式化数据的词法分析器/标记器。
示例用法
RTFLex 允许您轻松地从 RTF 格式化文件中提取纯文本。以下是如何操作的
require_once "rtflex/RTFLexer.php";
use RTFLex\io\StreamReader;
use RTFLex\tokenizer\RTFTokenizer;
use RTFLex\tree\RTFDocument;
$reader = new StreamReader('/path/to/myFile.rtf');
$tokenizer = new RTFTokenizer($reader);
$doc = new RTFDocument($tokenizer);
echo $doc->extractText();
尽管 RTFLex 使用命名空间来组织其内部工作,但它还提供了一个简单、全局的前端类,便于使用。这和上面的代码完成的是同样的事情
require_once "rtflex/RTFLexer.php";
$doc = RTFLexer::file('/path/to/myFile.rtf');
echo $doc->extractText();
RTFLex 还允许您轻松地从 RTF 文件中提取隐藏的元数据。以以下 RTF 标头为例
{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf370
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\info
{\title Sample Title}
{\subject Sample Subject}
{\author Craig Weber}
{\*\company silvermine}
{\*\copyright 2013 silvermine.}}\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
...
使用 RTFDocument 类,很容易提取这些字段。
$doc = RTFLexer::file('/path/to/myFile.rtf');
echo $doc->extractMetadata('title'); // => "Sample Title"
echo $doc->extractMetadata('copyright'); // => "2013 silvermine."