Page 1 of 1

[SOLVED] Filtering the output of an array

Posted: Fri Dec 16, 2005 10:11 pm
by Daisy Cutter
I've got an array output code that looks like this:

Code: Select all

foreach ($Array as $key => $val) {
$band = array("bad","words","here");
if(strpos($val, $band) !== FALSE) {
$val = str_replace($band,"***",$val);
echo $val; }
else {
echo $val;
} 
echo "<br />"; }
I want that to be able to take any words in the $band array and if they are found, replace them with ***.

If I change $band in the strpos() and str_repace() functions with a word in quotes, like "hello" it works, but using the array variable does not.

Could anyone tell me how I could achieve this goal?
Thanks!

Posted: Fri Dec 16, 2005 10:31 pm
by Daisy Cutter
nevermind... what a fool i was being :oops:

Code: Select all

foreach ($Array as $key => $val) { 
$band = array("bad","words","here"); 
$val = str_replace($band,"***",$val); 
echo $val;
echo "<br />"; }
That works just fine. No idea why I decided to try and check if the string was found first, since if it wasn't there it wouldn't be replaced anyway. I guess it's just been a long day.