kafene / netscape-bookmark-parser
通用Netscape书签解析器
v0.0.1
2015-09-17 22:20 UTC
This package is not auto-updated.
Last update: 2024-09-24 04:12:32 UTC
README
关于
此库提供了一个通用的 NetscapeBookmarkParser
类,该类能够解析Netscape书签导出文件。
开发此解析器的动机如下
- Netscape格式 具有非常宽松的规范:没有 DTD 也无 XSL样式表 来约束数据的格式
- 软件和Web服务导出书签时使用了各种不同的属性名称和值
- 因此使用标准的SAX或DOM解析器并不直接。
它的工作原理
- 输入书签文件被裁剪和清理以提高解析结果
- 然后使用 PCRE 模式来匹配最可能的属性名称对应的属性和值
- 属性名称:如
description
与note
,tags
与labels
,date
与time
等。 - 数据格式:如
comma,separated,tags
与space separated labels
,UNIX时间戳与可读日期,换行符与回车符等。
- 属性名称:如
- 返回一个包含所有成功解析的链接及其属性的关联数组
示例
脚本
<?php require_once 'NetscapeBookmarkParser.php'; $parser = new NetscapeBookmarkParser(); $bookmarks = $parser->parseFile('./tests/input/netscape_basic.htm'); var_dump($bookmarks);
输出
array(2) {
[0] =>
array(6) {
'tags' =>
string(14) "private secret"
'uri' =>
string(19) "https://private.tld"
'title' =>
string(12) "Secret stuff"
'note' =>
string(52) "Super-secret stuff you're not supposed to know about"
'time' =>
int(971175336)
'pub' =>
int(0)
}
[1] =>
array(6) {
'tags' =>
string(18) "public hello world"
'uri' =>
string(17) "http://public.tld"
'title' =>
string(12) "Public stuff"
'note' =>
string(0) ""
'time' =>
int(1456433748)
'pub' =>
int(1)
}
}