Remove commas from within quotes in a CSV

A client has software which does not honour commas within quotes. So all commas within quotes need to be removed before the CSV export is sent to the client.

This function would be called for each line in the csv.

$csv_data is the CSV to be parsed
$replace_char is what to replace the comma with. It defaults to a space.

function remove_commas($csv_data, $replace_chr = ' ')
{
	$arr_csv = str_getcsv($csv_data,',','"');

	foreach( $arr_csv as $key => $value )
	{
		$arr_csv[$key] = str_replace(",",$replace_chr, $value);
	}

	return implode(',', array_map(function($str){ return sprintf("\"%s\"", $str); }, $csv_data));
}