'v_categories_name_1', 'LongDescription' => 'v_products_description_1' ); // search phrase => replacement phrase $categories = array( 'FLOPPY DISK DRIVES' => 'Disk Drives', 'IDE DISK DRIVES' => 'Disk Drives', 'STORAGE MISC' => 'Disk Drives', 'MODEMS - GENERAL' => 'Communications', 'GRAPHICS CARDS' => 'Graphics Cards', 'PC CASES' => 'Cases', 'MEMORY' => 'Memory', 'GENERAL MEDIA' => 'Media', 'CPUS' => 'CPUs', 'PC ACCESSORIES' => 'Accessories', 'MISC SOFTWARE' => 'Software', 'SCSI DISK DRIVES' => 'Disk Drives', 'PRINTER INKS' => 'Printer Consumables', 'PRINTER PAPER' => 'Printer Consumables', 'OPTICAL DRIVES' => 'DVD/CD', 'MULTIMEDIA SPEAKERS' => 'Speakers', 'SOUNDCARDS' => 'Soundcards', 'PREMIER CAMERAS' => 'Digital Cameras', 'KEYBOARDS' => 'Keyboards', 'TV TUNERS' => 'TV Tuners', 'MOTHERBOARDS' => 'Motherboards', 'NETWORKING' => 'Networking', 'CNET PRODUCTS' => 'Networking', 'MONITORS' => 'Monitors', 'MOTHERBOARD ACCESSOR' => 'Motherboards', 'RACKMOUNT SERVERS' => 'Networking', 'NOTEBOOKS' => 'Laptops' ); // open up source CSV file $csv = "bdt.csv"; // CSV file to be read and modified $fh = fopen($csv, 'r') or die("Could not open file"); // initialize data array $data = array(); $line = fgetcsv($fh,2000); for($i=0; $i < count($line); $i++) { if(isset($headers[$line[$i]])) { $line[$i] = $headers[trim($line[$i])]; } } $data[] = $line; // loop through each line in source file while(($line = fgetcsv($fh,2000)) !== FALSE) { if(isset($line[2])) { // look for search values and replace them when found: $line[2] = str_replace(array_keys($categories), $categories, $line[2]); } $line[] = 'EOREOR'; $data[] = $line; // add to data array } fclose($fh); // write data array to new CSV file: $newfile = 'data_fixed.csv'; $fh = fopen($newfile, 'w') or die("Could not open new file"); foreach($data as $line) { // use implode to create comma-separated line: fwrite($fh, implode(',', $line)."\n"); } fclose($fh); echo "

Revised data saved as $newfile.

"; ?>