php同義詞替換的實現(xiàn)方法:首先創(chuàng)建一個php示例文件;然后定義一個“strtr_words”方法;接著通過“file_get_contents”函數(shù)獲取詞庫;最后通過“explode”等函數(shù)方法實現(xiàn)同義詞替換即可。
推薦:《php視頻教程》
php實現(xiàn)seo偽原創(chuàng)同義詞替換函數(shù)
近日和一朋友討論php關(guān)于同義詞替換的seo偽原創(chuàng)問題,寫了如下函數(shù),并為emlog做成插件。
function strtr_words($str){$words=array();$content = file_get_contents(‘words.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);//關(guān)鍵詞分割符$words =array(“$str_data[0]“=>”$str_data[1]“);}}return strtr($str,$words);//返回結(jié)果}詞庫words.txt格式如下:
懇求→哀求悲悼→哀傷悲痛→哀思悲傷→哀痛順序→挨次受餓→挨餓靠攏→挨近注意,每一行一組同義詞,中間用“→”分割。