Skip to content

Commit dc44696

Browse files
committed
chore/add v3.1 upgrade notes
1 parent 18b9c33 commit dc44696

1 file changed

Lines changed: 37 additions & 26 deletions

File tree

README.md

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
Unstructured Text Parser [PHP]
2-
===========================================
1+
# Unstructured Text Parser [PHP]
2+
33
[![Tests](https://github.com/aymanrb/php-unstructured-text-parser/actions/workflows/php.yml/badge.svg)](https://github.com/aymanrb/php-unstructured-text-parser/actions/workflows/php.yml)
44
[![Latest Stable Version](https://poser.pugx.org/aymanrb/php-unstructured-text-parser/v/stable.svg)](https://packagist.org/packages/aymanrb/php-unstructured-text-parser)
55
[![Total Downloads](https://poser.pugx.org/aymanrb/php-unstructured-text-parser/downloads)](https://packagist.org/packages/aymanrb/php-unstructured-text-parser)
66
[![License](https://poser.pugx.org/aymanrb/php-unstructured-text-parser/license.svg)](https://packagist.org/packages/aymanrb/php-unstructured-text-parser)
77

8-
About Unstructured Text Parser
9-
----------------------------------
10-
This is a small PHP library to help extract text out of documents that are not structured in a processing friendly format.
11-
When you want to parse text out of form generated emails for example you can create a template matching the expected incoming mail format
8+
## About Unstructured Text Parser
9+
10+
This is a small PHP library to help extract text out of documents that are not structured in a processing friendly format.
11+
When you want to parse text out of form generated emails for example you can create a template matching the expected incoming mail format
1212
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.
1313

1414
Useful when you want to parse data out of:
15-
* Emails generated from web forms
16-
* Documents with definable templates / expressions
1715

18-
Installation
19-
----------
20-
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.
16+
- Emails generated from web forms
17+
- Documents with definable templates / expressions
18+
19+
## Installation
20+
21+
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.
2122

2223
Requirements:
24+
2325
- PHP 8.1 or newer
2426

2527
Install it with Composer:
@@ -28,9 +30,8 @@ Install it with Composer:
2830
composer require aymanrb/php-unstructured-text-parser
2931
```
3032

33+
## [Usage example](https://github.com/aymanrb/php-unstructured-text-parser/blob/master/examples/run.php)
3134

32-
[Usage example](https://github.com/aymanrb/php-unstructured-text-parser/blob/master/examples/run.php)
33-
----------
3435
```php
3536
<?php
3637
include_once __DIR__ . '/../vendor/autoload.php';
@@ -51,26 +52,26 @@ print_r(
5152
);
5253
```
5354

54-
Parsing Procedure
55-
----------
55+
## Parsing Procedure
56+
5657
1- Grab a single copy of the text you want to parse.
5758

58-
2- Replace every single varying text within it to a named variable in the form of ``{%VariableName%}`` if you want to match
59-
everything in this part of text or ``{%VariableName:Pattern%}`` if you want to match a specific set of characters or use a more
59+
2- Replace every single varying text within it to a named variable in the form of `{%VariableName%}` if you want to match
60+
everything in this part of text or `{%VariableName:Pattern%}` if you want to match a specific set of characters or use a more
6061
precise pattern.
6162

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

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

66-
Template Example
67-
------------------------
67+
## Template Example
68+
6869
If the text documents you want to parse looks like this:
6970

7071
```
7172
Hello,
7273
If you wish to parse message coming from a website that states info like:
73-
ID & Source: 12234432 Website Form
74+
ID & Source: 12234432 Website Form
7475
Name: Pet Cat
7576
E-Mail: email@example.com
7677
Comment: Some text goes here
@@ -80,7 +81,7 @@ Best Regards
8081
Admin
8182
```
8283

83-
Your Template file (``example_template.txt``) could be something like:
84+
Your Template file (`example_template.txt`) could be something like:
8485

8586
```
8687
Hello,
@@ -107,11 +108,21 @@ Array(
107108
)
108109
```
109110

110-
Upgrading from v1.x to v2.x
111-
------------------------
111+
## Upgrading from v2.x to v3.1.0
112+
113+
- **PHP 8.1+ required**: The PHP 7.4 support is dropped.
114+
- **New exceptions may be thrown**: `InvalidTemplateVariableNameException` is thrown for template variables with invalid PCRE capture group names; `InvalidTemplateSyntaxException` is thrown for templates that produce an invalid regex. Both extend `UnstructuredTextParserException`.
115+
- **Empty input to `parseText()` is short-circuited**: passing an empty or whitespace-only string returns an empty `ParseResult` immediately.
116+
- **`ParseResult` now implements `Countable` and `IteratorAggregate`**: you can now use `count($result)` and `foreach ($result as $key => $value)` directly instead of going through `getParsedRawData()`.
117+
- **`getOrFail(string $key)`** method was added to `ParseResult` as a shorthand for `get($key, true)`.
118+
119+
---
120+
121+
## Upgrading from v1.x to v2.x
122+
112123
Version 2.0 is more or less a refactored copy of version 1.x of the library and provides the exact same functionality.
113124
There is just one slight difference in the results returned. It's now a parsed data object instead of an array.
114-
To get the results as an array like it used to be in v1.x simply call "*getParsedRawData()*" on the returned object.
125+
To get the results as an array like it used to be in v1.x simply call "_getParsedRawData()_" on the returned object.
115126

116127
```php
117128
<?php
@@ -120,4 +131,4 @@ $extractedArray = $parser->parseText($textToParse);
120131

121132
//In 2.x you need to do the following if you want an array
122133
$extractedArray = $parser->parseText($textToParse)->getParsedRawData();
123-
```
134+
```

0 commit comments

Comments
 (0)