【发布时间】:2010-08-05 14:13:33
【问题描述】:
所以我有一个如下所示的 CSV 文件:
12345, Here is some text
20394, Here is some more text
我怎样才能将它插入一个看起来像这样的数组中
$text = "12345" => "Here is some text",
"20394" => "Here is some more text";
这是我目前必须在一层 CSV 上获得基于单个数值的值
if ($handle = fopen("$qid", "r")) {
$csvData = file_get_contents($qid);
$csvDelim = "\r";
$qid = array();
$qid = str_getcsv($csvData, $csvDelim);
} else {
die("Could not open CSV file.");
}
感谢您的回复,但我仍然看到一个潜在的问题。使用这些解决方案,值不会以这种方式存储:
$array[0] = 12345
$array[1] = Here is some text 20394
$array[2] = Here is some more text
如果我在上面的示例 csv 上尝试此操作,数组将如何构造?
【问题讨论】:
-
文本中是否出现逗号?
-
你的分隔符应该是
',',而不是"\r" -
你问什么......这不可能,计算机没有这种黑魔法的能力。您需要用汇编程序编写数千行代码,并且您的计算机中至少有 16 个内核才能尝试它。