Voting

: min(five, one)?
(Example: nine)

The Note You're Voting On

flame2000 at mail dot ru
10 years ago
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;
} 
//examples:
$from="fotber, ";
$to="berfot+_";
// or
$from=array("f","o","t","b","e","r",","," ");
$to=array("b","e","r","f","o","t","+","_");
//out:
echo mb_chars_replace($from,$to,"foot, beer"); //beer+foot
?>

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /