A csv file contains a '\' character in one of its record for which i am not able to get the exact number of key value pair in the array.
I am using PHP fgetcsv function as follows-
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
....
}
I have also tried escaping the characters as follows.
while (($data = fgetcsv($handle, 1000, ",",'"',"\\")) !== FALSE) {
....
}
But it did not work.What might be the possible solution?
PHP fgetcsv() Function$file = fopen("contacts. csv","r"); print_r(fgetcsv($file)); fclose($file);
PHP empty() Function The empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true.
I had the same problem, and solve it too easy. If your string enclosure charater is '"' ( double quotes ), and you just don't want to consider the backslash as a escape character, just inform the double quote twice, as the string enclusure and as a escape character.
$data = fgetcsv($handle, 8192, ';' , '"' , '"' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With