Skip to content

Commit 8b368db

Browse files
authored
Merge pull request #14 from aymanrb/v2.0
Version 2.0 (Upgrade to PHP7)
2 parents 078d64c + 955c08f commit 8b368db

25 files changed

+2085
-877
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ examples/Logs/*
4141
######################
4242
!empty
4343
!.gitkeep
44+
45+
46+
# PHP Unit #
47+
######################
48+
.phpunit.result.cache
49+
/cache.properties
50+
tests/_reports/*
51+
build/logs/*

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
6-
- 7.1
4+
- 7.2
5+
- 7.3
76

87
matrix:
98
fast_finish: true
@@ -14,6 +13,9 @@ before_script:
1413

1514
script: phpunit tests --coverage-clover=coverage.xml
1615

16+
after_success:
17+
- travis_retry php vendor/bin/php-coveralls
18+
1719
notifications:
1820
on_success: never
1921
on_failure: always

README.md

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
Unstructured Text Parser [PHP]
22
===========================================
33
[![Build Status](https://travis-ci.org/aymanrb/php-unstructured-text-parser.svg?branch=master)](https://travis-ci.org/aymanrb/php-unstructured-text-parser)
4+
[![Coverage Status](https://coveralls.io/repos/github/aymanrb/php-unstructured-text-parser/badge.svg?branch=master)](https://coveralls.io/github/aymanrb/php-unstructured-text-parser?branch=master)
45
[![Latest Stable Version](https://poser.pugx.org/aymanrb/php-unstructured-text-parser/v/stable.svg)](https://packagist.org/packages/aymanrb/php-unstructured-text-parser)
56
[![Latest Unstable Version](https://poser.pugx.org/aymanrb/php-unstructured-text-parser/v/unstable.svg)](https://packagist.org/packages/aymanrb/php-unstructured-text-parser)
67
[![License](https://poser.pugx.org/aymanrb/php-unstructured-text-parser/license.svg)](https://packagist.org/packages/aymanrb/php-unstructured-text-parser)
78

89

9-
About this Class
10+
About Unstructured Text Parser
1011
----------------------------------
11-
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.
12+
This is a small PHP library to help extract text out of documents that are not structured in a processing friendly format.
13+
When you want to parse text out of form generated emails for example you can create a template matching the expected incoming mail format
14+
while specifying the variable text elements and leave the rest for the class to extract your pre-formatted variables out of the incoming mails' body text.
1215

1316
Useful when you want to parse data out of:
1417
* Emails generated from web forms
1518
* Documents with definable templates / expressions
1619

1720
Installation
1821
----------
22+
PHP Unstructured Text Parser is available on [Packagist](https://packagist.org/packages/aymanrb/php-unstructured-text-parser) (using semantic versioning), and installation via [Composer](https://getcomposer.org) is recommended.
23+
Add the following line to your `composer.json` file:
1924

20-
#### 1- Using [composer](https://getcomposer.org/) simply run the following:
21-
22-
```shell
23-
$ composer require aymanrb/php-unstructured-text-parser
25+
```json
26+
"aymanrb/php-unstructured-text-parser": "~2.0"
2427
```
2528

26-
#### 2- Clone / Copy the files from this repository to your local libs directory:
29+
or run
2730

28-
```shell
29-
$ git clone https://github.com/aymanrb/php-unstructured-text-parser.git
31+
```sh
32+
composer require aymanrb/php-unstructured-text-parser
3033
```
3134

3235

33-
3436
[Usage example](https://github.com/aymanrb/php-unstructured-text-parser/blob/master/examples/run.php)
3537
----------
3638
```php
@@ -41,11 +43,16 @@ $parser = new aymanrb\UnstructuredTextParser\TextParser('/path/to/templatesDirec
4143

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

44-
//performs brute force parsing against all available templates
45-
print_r($parser->parseText($textToParse));
46+
//performs brute force parsing against all available templates, returns first match successful parsing
47+
$parseResults = $parser->parseText($textToParse);
48+
print_r($parseResults->getParsedRawData());
4649

47-
//slower, performs a similarity check on available templates before parsing
48-
print_r($parser->parseText($textToParse, true));
50+
//slower, performs a similarity check on available templates to select the most matching template before parsing
51+
print_r(
52+
$parser
53+
->parseText($textToParse, true)
54+
->getParsedRawData()
55+
);
4956
```
5057

5158
Parsing Procedure
@@ -74,13 +81,13 @@ Best Regards
7481
Admin
7582
```
7683

77-
Then your Template file (``example_template.txt``) should be:
84+
Your Template file (``example_template.txt``) could be something like:
7885

7986
```
80-
Hi {%name_of_receiver%},
87+
Hi {%nameOfRecipient%},
8188
If you wish to parse message coming from a website that states info like:
82-
Name: {%sender_name%}
83-
E-Mail: {%sender_email%}
89+
Name: {%senderName%}
90+
E-Mail: {%senderEmail%}
8491
Comment: {%comment%}
8592
8693
Thank You,
@@ -92,9 +99,24 @@ The output of a successful parsing job would be:
9299

93100
```
94101
Array(
95-
'name_of_receiver' => 'GitHub-er',
96-
'sender_name' => 'Pet Cat',
97-
'sender_email' => 'email@example.com',
98-
'Comment' => 'Some text goes here'
102+
'nameOfRecipient' => 'GitHub-er',
103+
'senderName' => 'Pet Cat',
104+
'senderEmail' => 'email@example.com',
105+
'comment' => 'Some text goes here'
99106
)
100107
```
108+
109+
Upgrading from v1.3 to v2.0
110+
------------------------
111+
Version 2.0 is more or less a refactored copy of version 1.x of the library and provides the exact same functionality.
112+
There is just one slight difference in the results returned. It's now a parsed data object instead of an array.
113+
To get the results as an array like it used to be in v1.x simply call "*getParsedRawData()*" on the returned object.
114+
115+
```php
116+
<?php
117+
//ParseText used to return array in 1.x
118+
$extractedArray = $parser->parseText($textToParse);
119+
120+
//In 2.x you need to do the following if you want an array
121+
$extractedArray = $parser->parseText($textToParse)->getParsedRawData();
122+
```

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aymanrb/php-unstructured-text-parser",
3-
"description": "A PHP Class to help extract text out of documents that are not structured in a processing friendly manner",
3+
"description": "A PHP library to help extract text out of text documents",
44
"keywords": [
55
"text parser",
66
"extract data",
@@ -12,10 +12,10 @@
1212
],
1313
"config": {
1414
"platform": {
15-
"php": "5.6.0"
15+
"php": "7.3.0"
1616
}
1717
},
18-
"version": "1.3.0",
18+
"version": "2.0.0",
1919
"type": "library",
2020
"license": "MIT",
2121
"authors": [
@@ -48,11 +48,11 @@
4848
},
4949
"require": {
5050
"ext-json": "*",
51-
"php": ">=5.6.0",
52-
"monolog/monolog": "^1.24",
51+
"php": ">=7.1.0",
5352
"psr/log": "^1.1"
5453
},
5554
"require-dev": {
56-
"phpunit/phpunit": "^5.0"
55+
"phpunit/phpunit": "^8.0",
56+
"php-coveralls/php-coveralls": "^2.1"
5757
}
5858
}

0 commit comments

Comments
 (0)