You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
12
12
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.
13
13
14
14
Useful when you want to parse data out of:
15
-
* Emails generated from web forms
16
-
* Documents with definable templates / expressions
17
15
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.
1- Grab a single copy of the text you want to parse.
57
58
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
60
61
precise pattern.
61
62
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`
63
64
64
65
4- Pass the text you wish to parse to the parse method of the class and let it do the magic for you.
65
66
66
-
Template Example
67
-
------------------------
67
+
## Template Example
68
+
68
69
If the text documents you want to parse looks like this:
69
70
70
71
```
71
72
Hello,
72
73
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
74
75
Name: Pet Cat
75
76
E-Mail: email@example.com
76
77
Comment: Some text goes here
@@ -80,7 +81,7 @@ Best Regards
80
81
Admin
81
82
```
82
83
83
-
Your Template file (``example_template.txt``) could be something like:
84
+
Your Template file (`example_template.txt`) could be something like:
84
85
85
86
```
86
87
Hello,
@@ -107,11 +108,21 @@ Array(
107
108
)
108
109
```
109
110
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
+
112
123
Version 2.0 is more or less a refactored copy of version 1.x of the library and provides the exact same functionality.
113
124
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.
0 commit comments