Remove unwanted words from string
<p>I have a csv file to read, but in one column there are some unwanted words.
It's easier to write the needed words into an whitelist array, than to make a blacklist.
This is what I tried, but i get an empty cell.
The following script is only used when the cell index is 5 (the column that I need to modify).</p>

<pre><code>$whitelist[0] = "BLACK";
$whitelist[1] = "RED";
$whitelist[2] = "ON";
$whitelist[3] = "BLUE";
$whitelist[4] = "COLOR";
$whitelist[5] = "YELLOW";
$whitelist[6] = "GREEN";
$whitelist[7] = "CYAN";
$whitelist[8] = "MAGENTA";
foreach( $csv_line as $row ){
    $cell = explode(' ', $row[0]);
    foreach($cell as $b=&gt;$v)
        if( !in_array($cell, $whitelist) )
            unset( $cell[$b] );
            $row[0] = implode(' ', $cell);
}  echo "&lt;td&gt;".$row[0]."&lt;/td&gt;";
</code></pre>

<p>Any tips will be appreciated.</p>

<p>Thanks,
Sebastian</p>
