class wycClass { private $replaced = array(); private $dicts = array(); function __construct() { $this->dicts = require(dirname(__FILE__).'/dict.php'); } function replace($text) { foreach($this->dicts as $key => $val) { if(preg_match(“/”.$key.”/”, $text) && !in_array($key, $this->replaced)) { $text = str_replace($key, $val, $text); array_push($this->replaced, $val); } } return $text; } }
dict.php '言而不行', '言而不行' => '光说不做', '罪有应得' => '咎由自取', '咎由自取' => '罪有应得', '黑沉沉' => '黑洞洞', '黑洞洞' => '黑沉沉', '黑魆魆' => '黑沉沉', '黑糊糊' => '黑沉沉', '黑黝黝' => '黑沉沉', '典礼' => '仪式', '仪式' => '典礼', '封锁' => '封闭', '封闭' => '封锁', '数量' => '数目', '数目' => '数量', '改行' => '转业', '转业' => '改行', '豪举' => '壮举', '壮举' => '豪举', '纯挚' => '纯真', '纯真' => '纯挚', '戳穿' => '揭穿', '揭穿' => '戳穿', '慈爱' => '慈祥', '慈祥' => '慈爱', '次序' => '顺序', '顺序' => '次序', '聪慧' => '聪明', '聪明' => '聪慧', '聪颖' => '伶俐', '伶俐' => '聪颖', '葱茏' => '葱郁', '洪亮' => '响亮', '嘹亮' => '响亮', '消费' => '花费', '花费' => '消费', '呼叫' => '呼唤', '呼唤' => '呼叫', '村庄' => '村落', '村落' => '村庄', '村子' => '村里', '村里' => '村子', '真心' => '真诚', '祝福' => '祝愿', '呵呵' => '嘿嘿', '功效' => '功用', '材质' => '材料', '材料' => '材质', '尺码' => '尺寸', '尺寸' => '尺码', '销售' => '出售', '出售' => '销售', '店主' => '掌柜', '掌柜' => '店主',);]]>
php实现伪原创示例:等您坐沙发呢!