span style="color: #0000BB"><?phpfunction trans($a) { $b = array('a','b','v','g','d','e'); $g = array('а','б','в','г','д','е'); return str_replace($b,$g,$a);}function bb_trans($text) { $find = array('~\[ru\](.*?)\[/ru\]~s'); $replace = array(trans('$1')); return preg_replace($find,$replace,$text);}$text = 'abvgd [ru] abvgd [/ru] abvgd';echo bb_trans($text); |
span style="color: #0000BB"><?phpfunction trans($str) { return str_replace( array('a','b','v','g','d','e'), array('а','б','в','г','д','е'), $str );} function bb_trans($text) { return preg_replace_callback('~\[ru\](.*?)\[/ru\]~si', function ($matches) { return '[ru]' . trans($matches[1]) . '[/ru]'; }, $text);}$text = 'abvgd [ru] abvgd [/ru] abvgd';echo bb_trans($text); |