note 119930 added to function.str-replace

From: Date: Wed, 21 Sep 2016 19:17:07 +0000
Subject: note 119930 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-206649@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 72.52.91.14 Probable Submitter: 95.143.217.245 ---- Manual Page -- http://php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/119930 Del: integrated -- https://master.php.net/note/delete/119930/integrated Del: useless -- https://master.php.net/note/delete/119930/useless Del: bad code -- https://master.php.net/note/delete/119930/bad+code Del: spam -- https://master.php.net/note/delete/119930/spam Del: non-english -- https://master.php.net/note/delete/119930/non-english Del: in docs -- https://master.php.net/note/delete/119930/in+docs Del: other reasons-- https://master.php.net/note/delete/119930 Reject -- https://master.php.net/note/reject/119930 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206649) next »