php-aho is a PHP Extension for the multifast's Aho–Corasick algorithm.
phpize
./configure
make
sudo make install
define int aho_match(string $subject, &$matches)
method.
Enable php-aho
and set dict path in the ini file:
[aho]
extension=aho.so
aho.dict=/tmp/foo.dict
An example dict is like this:
apple`fruit
china`nation
smile`emotion
Use the ` as the separator.
And then:
Psy Shell v0.7.2 (PHP 7.0.8 — cli) by Justin Hileman
>>> aho_match ('apple from china make me smile', $matches)
=> 3
>>> $matches
=> [
[
0, # keyword offset
"apple", # keyword
"fruit", # keyword type
],
[
11,
"china",
"nation",
],
[
25,
"smile",
"emotion",
],
]
Enjoy yourself :).