README.md
57 lines
| 1 | [](https://packagist.org/packages/wikimedia/aho-corasick](https://packagist.org/packages/wikimedia/aho-corasick](https://packagist.org/packages/wikimedia/aho-corasick) |
| 2 | |
| 3 | AhoCorasick |
| 4 | =========== |
| 5 | |
| 6 | AhoCorasick is a PHP implementation of the [Aho-Corasick][1] string search |
| 7 | algorithm, which is an efficient way of searching a body of text for multiple |
| 8 | search keywords. |
| 9 | |
| 10 | Here is how you use it: |
| 11 | |
| 12 | <pre lang="php"> |
| 13 | use AhoCorasick\MultiStringMatcher; |
| 14 | |
| 15 | $keywords = new MultiStringMatcher( array( 'ore', 'hell' ) ); |
| 16 | |
| 17 | $keywords->searchIn( 'She sells sea shells by the sea shore.' ); |
| 18 | // Result: array( array( 15, 'hell' ), array( 34, 'ore' ) ) |
| 19 | |
| 20 | $keywords->searchIn( 'Say hello to more text. MultiStringMatcher objects are reusable!' ); |
| 21 | // Result: array( array( 4, 'hell' ), array( 14, 'ore' ) ) |
| 22 | </pre> |
| 23 | |
| 24 | |
| 25 | Features |
| 26 | -------- |
| 27 | |
| 28 | The algorithm works by constructing a finite-state machine out of the set of |
| 29 | search keywords. The time it takes to construct the finite state machine is |
| 30 | proportional to the sum of the lengths of the search keywords. Once |
| 31 | constructed, the machine can locate all occurences of all search keywords in |
| 32 | any body of text in a single pass, making exactly one state transition per |
| 33 | input character. |
| 34 | |
| 35 | |
| 36 | Contribute |
| 37 | ---------- |
| 38 | |
| 39 | - Issue tracker: <https://phabricator.wikimedia.org/tag/ahocorasick/> |
| 40 | - Source code: https://github.com/wikimedia/AhoCorasick |
| 41 | |
| 42 | |
| 43 | Support |
| 44 | ------- |
| 45 | |
| 46 | If you are having issues, [please let us know][2]. |
| 47 | |
| 48 | |
| 49 | License |
| 50 | ------- |
| 51 | |
| 52 | The project is licensed under the Apache license. |
| 53 | |
| 54 | |
| 55 | [1]: https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm |
| 56 | [2]: https://phabricator.wikimedia.org/maniphest/task/create/?projects=PHID-PROJ-hs5ausnvlfs4e3n5gmzg |
| 57 |