(使用PHP)
我需要检查客户上传的CSV文件。具体来说,我需要验证此CSV是否具有“;”分隔符不允许使用其他分隔符。
为您处理此问题的最佳方法是什么?
谢谢。
答案 0 :(得分:0)
如果你知道第一行的值,你可以尝试通过读取第一行的第N个字符来识别分隔符,例如:
$csvdata = "delimiter;test\r\netc;herp"; // Contents of the uploaded file
$delimiter = substr($csvdata, strlen("delimiter "), 1);
echo $delimiter;
我建议你使用xlsx文件类型。它比CSV更容易处理,并且没有Mac和DOS行结尾和编码的问题。