您好我在excel中有这种格式的数据。
/**
* Gets the Amount of Degress of rotation using the exif integer to determine how much
* we should rotate the image.
* @param exifOrientation - the Exif data for Image Orientation
* @return - how much to rotate in degress
*/
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; }
else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }
return 0;
}
我把它保存为csv,我得到逗号分隔值。我需要从C列中删除一些项目。例如,我需要删除Laravel和Codeigniter,其他数据不变。我怎么能这样做?我试过这个代码。但是这会删除指定值的整行。
A B C
php Html Laravel
mysql Css Wordpress
javascript jquery Codeigniter
所以,当我运行它时,它不仅会删除Laravel'还有整个行 - php,Html,Laravel。
如何在不损害csv文件中的其他数据的情况下搜索和删除列中的多个值?
答案 0 :(得分:0)
这是因为如果该行包含Laravel,您将PHP告诉continue
(跳过fputcsv()
代码行),因此它根本不会写任何一行
$table = fopen('tech.csv','r');
$temp_table = fopen('table_temp.csv','w');
$names = ['Laravel', 'Codeigniter']; // The values that you're looking to remove
// (as an array of values)
while (($data = fgetcsv($table, 1000)) !== FALSE){
$data = array_diff($data, $names);
fputcsv($temp_table,$data);
}
fclose($table);
fclose($temp_table);
rename('table_temp.csv','tech.csv');