Replace chars in multi-byte string.
In example, replacing 'f'=>'b', 'o'=>'e', 't'=>'r' and etc.
<?php
function mb_chars_replace($from, $to, $subj, $delSymb='_') {
$nsubj='';
preg_match_all('/(.)/u', $subj, $subj);$subj=$subj[1];
if (!is_array($from)) {preg_match_all('/(.)/u', $from, $from);$from=$from[1];}
if (!is_array($to)) {preg_match_all('/(.)/u', $to, $to);$to=$to[1];}
if (count($from)!==count($to)) return false;
foreach($subj as $s) {
foreach($from as $k=>$f) {
if($s===$f) {
$s=$to[$k];
break;
}
}
if($s!==$delSymb) $nsubj.=$s;
}
return $nsubj;
}
$from="fotber, ";
$to="berfot+_";
$from=array("f","o","t","b","e","r",","," ");
$to=array("b","e","r","f","o","t","+","_");
echo mb_chars_replace($from,$to,"foot, beer"); ?>