fgetcsv()错误地将双引号添加到第一行的第一个元素
I have a very curious issue whith fgtcsv(). Look at this code
我有一个非常好奇的问题,有fgtcsv()。看看这段代码
$csv_check = fopen(CSV_DIR.$this->db_table.".csv","r");
$data = fgetcsv($csv_check, 1000, $this->fields_terminated_by);
fclose($csv_check);
A print_r($data) outputs the following:
print_r($ data)输出以下内容:
array (
0 => '"program_id"',
1 => 'program_name',
2 => 'program_logo',
)
Curiously, $data[0] is double-quoted here... The original line in this CSV file looks like this:
奇怪的是,$ data [0]在这里是双引号...此CSV文件中的原始行如下所示:
"program_id";"program_name";"program_logo"
I don't get it at all... Counting the chars of $data[0] with strlen($data[0]) returns 15, even if wrongly quoted, it must be 12 chars... I'm very stunned...!
我根本得不到它...用strlen($ data [0])计算$ data [0]的字符会返回15,即使错误引用,它也必须是12个字符...我很震惊...!
Any ideas?!?
2 个解决方案
#1
1
I know this is an old topic, but as someone may come like me and try to figure out a solution, here is how to fix it.
我知道这是一个古老的话题,但是有人可能会像我一样试图找出解决方案,这里有解决方法。
Open notepad (in my case, I used notepad++) and create a new file.
Copy/paste all the data in the new file.
Save it as "All type" and add ".csv" yourself.
The file should be saved without BOM, and you can process with reading your CSV file with PHP.
打开记事本(在我的情况下,我使用notepad ++)并创建一个新文件。复制/粘贴新文件中的所有数据。将其保存为“所有类型”并自行添加“.csv”。应该保存文件而不使用BOM,您可以使用PHP读取CSV文件进行处理。
更多相关文章
- PHP实现字符串转换成查询语句
- mysql 判断null 和 空字符串
- Mysql字符集和校验规则
- MySQL数据库总结(8)字符集与校对集
- mysql字符集浅谈
- mysql主从同步报slave_sql_running:no的解决方案
- mysql如何判断一个字符串是否包含另外一个字符串?
- mySQL:按给定的ID字符串排序ID? (为分层数据构建面包屑)
- MySQL中find_in_set的用法(某个字段包含某个字符)