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文件进行处理。

更多相关文章

  1. PHP实现字符串转换成查询语句
  2. mysql 判断null 和 空字符串
  3. Mysql字符集和校验规则
  4. MySQL数据库总结(8)字符集与校对集
  5. mysql字符集浅谈
  6. mysql主从同步报slave_sql_running:no的解决方案
  7. mysql如何判断一个字符串是否包含另外一个字符串?
  8. mySQL:按给定的ID字符串排序ID? (为分层数据构建面包屑)
  9. MySQL中find_in_set的用法(某个字段包含某个字符)

随机推荐

  1. Linux下修改MySQL初始密码、开启远程登录
  2. Ubuntu下安装MySQL并实现远程登录?
  3. mysql执行update语句时报错:Data truncati
  4. 在Python中使用AWS Lambda使用MySQL时出
  5. Laravel 4中的多选过滤搜索
  6. php使用mysql数据库时中文不显示或显示异
  7. 简单的插入语句不能在PHP代码中工作。适
  8. 有办法在CodeIgniter中指定“使用索引”
  9. 如何将CSV文件中的值实际分割为MySQL数据
  10. win下远程连接linux下mysql