定制 dpolocalbrycej/php-unstructured-text-parser 二次开发

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

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

dpolocalbrycej/php-unstructured-text-parser

Composer 安装命令:

composer require dpolocalbrycej/php-unstructured-text-parser

包简介

A PHP Class to help extract text out of documents that are not structured in a processing friendly manner

README 文档

README

About this Class

This is a PHP Class to help extract text out of documents that are not structured in a processing friendly way. When you want to parse text out of form generated emails for example you can create a template matching the expected incoming mail format while specifying the variable text elements and leave the rest for the class to extract your preformatted variables out of the incoming mails' body text.

Useful when you want to parse data out of:

  • Emails generated from web forms
  • Documents with definable templates / expressions

Installation

1- Using composer simply run the following:

$ composer require dpolocalbrycej/php-unstructured-text-parser

####2- Clone / Copy the files from this repository to your local libs directory:

$ git clone https://github.com/dpolocalbrycej/php-unstructured-text-parser.git

Usage example

<?php
include_once __DIR__ . '/../vendor/autoload.php';

$parser = new dpolocalbrycej\UnstructuredTextParser\TextParser('/path/to/templatesDirectory');

$textToParse = 'Text to be parsed fetched from a file, mail, web service, or even added directly to the a string variable like this';

print_r($parser->parseText($textToParse)); //performs brute force parsing against all available templates

print_r($parser->parseText($textToParse, true)); //slower, performs a similarity check on available templates before parsing

Parsing Procedure

1- Grab a single copy of the text you want to parse.

2- Replace every single varying text within it to a named variable in the form of {%VariableName%}

3- Add the templates file into the templates directory (defined in parsing code) with a txt extension fileName.txt

4- Pass the text you wish to parse to the parse method of the class and let it do the magic for you.

Template Example

If the text documents you want to parse looks like this:

Hi GitHub-er,
If you wish to parse message coming from a website that states info like:
Name: Pet Cat
E-Mail: email@example.com
Comment: Some text goes here

Thank You,
Best Regards
Admin

Then your Template file (example_template.txt) should be:

Hi {%name_of_receiver%},
If you wish to parse message coming from a website that states info like:
Name: {%sender_name%}
E-Mail: {%sender_email%}
Comment: {%comment%}

Thank You,
Best Regards
Admin

The output of a successful parsing job would be:

Array(
    'name_of_receiver' => 'GitHub-er',
    'sender_name' => 'Pet Cat',
    'sender_email' => 'email@example.com',
    'Comment' => 'Some text goes here'
)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固