skyh13 / php-rtflex
此包的最新版本(0.4)没有可用的许可证信息。
一个简单的库,允许解析RTF文件和字符串。从silvermine/php-rtflex分支而来。
0.4
2016-06-02 13:42 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 4.8.*
This package is not auto-updated.
Last update: 2024-09-14 17:42:59 UTC
README
RTFLex是一个简单的RTF格式数据解析器/标记器。
使用示例
RTFLex允许您轻松地从RTF格式文件或包含RTF格式的文本字符串中提取纯文本。以下是如何读取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."