# simple-dictionary **Repository Path**: wangningkai/simple-dictionary ## Basic Information - **Project Name**: simple-dictionary - **Description**: 一个简单快速的词库工具 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-08-09 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Simple Dictionary ================== ### 一个简单快速的词库工具 ### 特点: > - **简单**:纯 PHP 实现,无需安装扩展。 > - **快速**:查找耗时跟词库大小关系不大,不会一次性加载整个词库,使用时内存占用小(生成词库比较耗费内存)。 ### 使用方法 #### 1.准备文本格式的词库 首先准备一个文本文件,每个词占一行。格式: ``` 词语值 词语值 词语值 词语值 词语值 词语值 ``` #### 2.使用SimpleDictionary生成词库 ``` composer require wangningkai\simple-dictionary dev-master ``` ```php search("some text here..."); # 返回结果 # $result = [ # 'word1' => ['value' => 'value1', 'count' => 'count1'], # ... # ] # ``` #### 替换 ```php replace("some text here...", "**"); #高级替换 $replaced = $dict->replace("some text here...", function($word, $value) { return "[$word -> $value]"; }); ```