require_once('parseWord.php'); class MemStore { private $mem=null; private $pat='#^[a-zA-Z]+\b#i';
public function __construct() { $this->mem=new Memcache(); $this->mem->connect("127.0.0.1", 11211) or die("connect memcached failed!!! "); } public function __destruct() { $this->mem->close(); } public function addWord() { $word=new Word('ciba.txt'); $word->readWord(); $result=$word->getWord(); //echo count($result)."字符 "; //exit(); foreach($result as $en => $ch) { $this->mem->add($en, $ch, MEMCACHE_COMPRESSED, time()+10*24*3600) or die("添加词条失败". __LINE__ ." "); } }
public function setWord($en,$ch) { //控制器判断输入是否合法 $en=$this->filterWord($en); $en=$this->mem->get($en) or die("找不到词条 $en"); $this->mem->set($en, $ch, MEMCACHE_COMPRESSED, time()+31*24*3600) or die("添加词条$en失败");
}
public function getWord($en) { //控制器判断输入是否合法 $en=$this->filterWord($en); $ch=$this->mem->get($en) or die("找不到词条 $en"); return $ch; }
public function replaceWord($en,$ch) { //控制器判断输入是否合法 $en=$this->filterWord($en); $en=$this->mem->get($en) or die("找不到词条 $en"); $this->mem->replace($en, $ch, MEMCACHE_COMPRESSED, time()+31*24*3600) or die("替换词条$en失败"); }
public function deleteWord($en) { //控制器判断输入是否合法 $en=$this->filterWord($en); $this->mem->delete($en,0) or die("删除词条$en失败"); }
//过滤掉中文,包括空格的词组,长度大于20的词条 public function filterWord($en) { $en=trim($en);
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn