note 46351 deleted from function.str-ireplace by aidan

From: Date: Fri, 08 Oct 2004 07:28:24 +0000
Subject: note 46351 deleted from function.str-ireplace by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78172@lists.php.net to get a copy of this message
Note Submitter: dj_helgegator at hotmail dot com ---- The function I found here didn't support arrays, so I made this one (compatible with PHP 3). Supports arrays and variables: <?php function str_ireplace($hwl_t, $hwl_r, $hwl_i){ for ($hwl_y = 0; $hwl_y < count($hwl_i); $hwl_y++){ if (is_array($hwl_i)) $hwl_ni = $hwl_i[$hwl_y]; else $hwl_ni = $hwl_i; for ($hwl_x = 0; $hwl_x < count($hwl_t); $hwl_x++){ if (is_array($hwl_t)) $hwl_nt = $hwl_t[$hwl_x]; else $hwl_nt = $hwl_t; if (is_array($hwl_r)) $hwl_nr = $hwl_r[$hwl_x]; else if ($hwl_x == 1) $hwl_nr = $hwl_r; else $hwl_nr = ""; $hwl_o = 0; do { $hwl_o = strpos(strtolower($hwl_ni), strtolower($hwl_nt), $hwl_o); if ($hwl_o !== false){ $hwl_ni = substr($hwl_ni, 0, $hwl_o) . $hwl_nr . substr($hwl_ni, $hwl_o+strlen($hwl_nt)); $hwl_o += strlen($hwl_nr); } } while ($hwl_o !== false); } if (is_array($hwl_i)) $hwl_i[$hwl_y] = $hwl_ni; else $hwl_i = $hwl_ni; } return $hwl_i; } ?> This is how it looks when I remove some code and make it only support variables: <?php function str_ireplace($hwl_t, $hwl_r, $hwl_i){ $hwl_o = 0; do { $hwl_o = strpos(strtolower($hwl_i), strtolower($hwl_t), $hwl_o); if ($hwl_o !== false){ $hwl_i = substr($hwl_i, 0, $hwl_o) . $hwl_r . substr($hwl_i, $hwl_o+strlen($hwl_t)); $hwl_o += strlen($hwl_r); } } while ($hwl_o !== false); return $hwl_i; } ?>

« previous php.notes (#78172) next »