I am creating csv using php like this Id,name,address,zip Some addresses have commas in them like Abc Street, #24H Comma in address is creating problem. Half of the address Abc street is in address column and remaining part of the address after comma #24H is in next column or box(zip). How i can fix that entire address appear in address column including comma.
The solution is to either escape the commas or filter them out before inserting the data into your CSV file. If a comma occurs within the data fields of a CSV file, the only reasonable option is to verify each line of data before processing it and either report the error or ignore the data.
Why not consider something other than commas as separators? Excel and oprn office work fine with other symbols such as tabs or semi-colons. I know that then becomes something other than a csv file, but does it matter? Guess it depends on whether you are using the output yourself or allowing downloads or auto-emailing it to others?
Use fputcsv() to wright you file. It is standard function that will take care of all special characters - no need to reinvent the wheel