AhoCorasick
PHP implementation of the Aho-Corasick string search algorithm
 All Classes Files Functions
AhoCorasick Documentation

AhoCorasick is a PHP implementation of the Aho-Corasick string search algorithm, which is an efficient way of searching a body of text for multiple search keywords.

Here is how you use it:

use AhoCorasick;
$keywords = new MultiStringMatcher( array( 'ore', 'hell' ) );
$keywords->searchIn( 'She sells sea shells by the sea shore.' );
// Result: array( array( 15, 'hell' ), array( 34, 'ore' ) )
$keywords->searchIn( 'Say hello to more text. MultiStringMatcher objects are reusable!' );
// Result: array( array( 4, 'hell' ), array( 14, 'ore' ) )

Features

The algorithm works by constructing a finite-state machine out of the set of search keywords. The time it takes to construct the finite state machine is proportional to the sum of the lengths of the search keywords. Once constructed, the machine can locate all occurences of all search keywords in any body of text in a single pass, making exactly one state transition per input character.

Contribute

Support

If you are having issues, please let us know.

License

The project is licensed under the Apache license.