replace string in array

From: Date: Fri, 14 Mar 2003 19:16:00 +0000
Subject: replace string in array
Groups: php.general 
Request: Send a blank email to php-general+get-139754@lists.php.net to get a copy of this message
I'm having a bit of trouble... I have an array that consists of a string like this: string1\rstring2\rstring3\rstring4 I want to REMOVE STRING3, and keep the rest of the array intact - but cannot figure on how to do it. I tried using functions such as preg_replace, strstr and so forth... In my code this is how I go thru the array... //snippet... //search for carriage return, split it... $line = preg_split( "/[\r]+/" ,$line); reset($line); //Line will consists of array... while (list ($key, $val) = each ($line)) { echo "<br>$key => $val"; if(strstr($val,$newmail)) { echo "<br>Found! and trying to delete....<br>"; //What to do form this point, I have the slightest foggy... } } It finds it without ANY problems, but I cannot seem to "go" to the position of found string, delete it, then keep the rest of the array. I did manage to find this on php.net, but it doesnt seem to work: function stri_replace2 ($search,$replace,$text) { if (!is_array($search)) { $search = array($search); $replace = array($replace); } foreach($search AS $key => $val) { $search["$key"] = '/'.quotemeta($val).'/i'; } echo "$search $replace $text"; return preg_replace($search,$replace,$text); } Could anyone help me with this? Thanks in advanced! Chris

« previous php.general (#139754) next »