Home  >  Article  >  Backend Development  >  排名不理想,实在没办法,再搞伪原创,谁有写好的函数分享下

排名不理想,实在没办法,再搞伪原创,谁有写好的函数分享下

WBOY
WBOYOriginal
2016-06-23 13:50:16937browse

排名不理想,实在没办法,再搞伪原创,谁有写好的函数分享下????

同义词表.txt
国内-中国
...........




实现, 发现国内换成中国, 发现中国换成国内....


如:           中国国内             
结果为:      国内中国





直接替换会变成     中国中国     或    国内国内    , 达不到效果
.


回复讨论(解决方案)

$d = array(  '国内' => '中国',  '中国' => '国内',);echo strtr('中国国内', $d);
国内中国

版主历害, 参考把网上的加多行代码, 立马行了

echo strtr_words('那个阿谁回结果成果百孔千疮-哀鸿遍野中人');function strtr_words($str){    $words=array();    $content = file_get_contents('_web/word.txt');//词库    $content = str_replace( "\r", "",$content); //去掉换行符(以便兼容Linux主机)    $content = preg_split('/\n/', $content, -1, PREG_SPLIT_NO_EMPTY);//\n分割字符        foreach($content as $k=>$v)        {            if($k!=0)            {                $str_data = explode('-',$v);//关键词分割符                $words+=array("$str_data[0]"=>"$str_data[1]");                $words+=array("$str_data[1]"=>"$str_data[0]");//多一行反向同义也替换            }        }    return strtr($str,$words);//返回结果}

Statement:
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