how to find out if csv file fields are tab delimited or comma delimited

后端 未结 15 1019
[愿得一人]
[愿得一人] 2020-12-01 09:46

how to find out if csv file fields are tab delimited or comma delimited. I need php validation for this. Can anyone plz help. Thanks in advance.

15条回答
  •  感动是毒
    2020-12-01 10:20

    There is no 100% reliable way to detemine this. What you can do is

    • If you have a method to validate the fields you read, try to read a few fields using either separator and validate against your method. If it breaks, use another one.
    • Count the occurrence of tabs or commas in the file. Usually one is significantly higher than the other
    • Last but not least: Ask the user, and allow him to override your guesses.

提交回复
热议问题