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).
$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=>$v)
if( !in_array($cell, $whitelist) )
unset( $cell[$b] );
$row[0] = implode(' ', $cell);
} echo "<td>".$row[0]."</td>";
Any tips will be appreciated.
Thanks,
Sebastian
change the line
if( !in_array($cell, $whitelist) )to
if( !in_array($v, $whitelist) )you want to check if the value
$vis not whitelisted, not the whole$cellarray