note 57132 deleted from function.str-replace by jome
| From: | jome@php.net | Date: | Sat, 24 Sep 2005 19:29:50 +0000 |
| Subject: | note 57132 deleted from function.str-replace by jome | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95725@lists.php.net to get a copy of this message | ||
Note Submitter: judofyr at gmail dot com
Reason: useless
----
Here i've made I function that is just like str_replace with if's, foreach's, explode
and implode:
function string_replace($from, $to, $in) {
$cfrom = count($from);
$cto = count($to);
if (is_array($from) && !is_array($to) || !is_array($from) && is_array($to) || $cto
!= $cfrom) {
return "error";
} else if (is_array($from) && is_array($to)) {
$i = 0;
$q = 0;
foreach ($from as $froms) {
foreach ($to as $tos) {
if ($q == $i) {
$ex = explode($froms, $in);
$in = implode($tos, $ex);
}
$i++;
}
$i = 0;
$q++;
}
return $in;
} else {
$ex = explode($from, $in);
$in = implode($to, $ex);
return $in;
}
}