定制 antevenio/stream-regex-iterator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

antevenio/stream-regex-iterator

最新稳定版本:0.0.4

Composer 安装命令:

composer require antevenio/stream-regex-iterator

包简介

PHP iterator of regex matches over streams

README 文档

README

Find regular expresion matches on seekable text streams and return them inside an iterator.

Description

This iterator comes as a solution to having to run complex multi line regular expressions on big files without exhausting memory.

The iterator will read chunks of data from the stream and run preg_match_all() on each one of them.

The iterator will read chunks of data in a way that it ensures no possible matches are lost through chunks, i.e. possible matches existing amidst chunk split points.

The iterator will return matches as preg_match_all() would do when using the PREG_SET_ORDER | PREG_OFFSET_CAPTURE flags.

Limitations

The specified stream must be fully seekable (back and forward).

The specified buffer size must be able to store the longest possible full match of the regexp.

The iterator will require approximately twice the specified buffer size memory.

Requirements

The following versions of PHP are supported.

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • PHP 7.2
  • PHP 7.3

Installation:

composer require antevenio/stream-regex-iterator

Usage

$inputString = "line1\nline2\nline3\nline4\nline5\nstart\nline6\nline7\nend";

$stream = fopen("data://text/plain," . $inputString, "r");

$matches = new Antevenio\StreamRegexIterator\Iterator(
    "/^start.*?end$/sm",
    $stream,
    32
);

foreach ($matches as $match) {
    print_r($match);
}

Would output:

Array
(
    [0] => Array
        (
            [0] => start
line6
line7
end
            [1] => 30
        )

)

统计信息

  • 总下载量: 13.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-16