git-mz / tkmatch
There is no license information available for the latest version (v1.1.0) of this package.
v1.1.0
2021-07-17 02:44 UTC
This package is auto-updated.
Last update: 2026-03-17 13:25:22 UTC
README
文本关键词匹配程序,主要采用DFA算法实现。
DFA算法
DFA 即 Deterministic Finite Automaton,也就是确定有穷自动机,它是是通过event和当前的state得到下一个state,即event+state=nextstate。更多关于DFA算法的了解可上网学习。
使用场景
v1.1.0
文本中匹配指定词组,替换为带链接的标签
使用方法
1、引入包
composer require git-mz/tkmatch
2、调用
use tkmatch\main;
$main = new Main();
$content = '我会脚踏云朵,哦不,是七彩云朵去娶你!';
$tags = [
['word' => '云朵', 'url' => 'www.yunduo.com'],
['word' => '七彩云朵', 'url' => 'www.qicaiyunduo.com'],
];
// 获取匹配到的tags
$res = $main::init()
->setTree($tags)
->getTagWord($content, $wordNum = 0);
// 替换匹配到的tags
$res = $main::init()
->setTree($tags)
->replace($content, $newclass = '', $replaceOne = 0);
3、方法说明
v1.1.0
getTagWord(String content, Int wordNum)
//获取文本中匹配到的标签
replace(String content, String newclass, Int replaceOne)
//匹配替换文本中的标签
小结一下
好好学习,天天向上! 代码不定期迭代...