我试图解析一个6000行500 KB文件到一个数组中,以便我可以将数据导入到我们的系统中。问题是脚本停止在3000-4000行之间的某处执行。代码没有中断,我们在其他进口上使用它。任何想法,为什么这可能会发生,我可以做些什么来防止它?脚本死亡,我不知道为什么
/**
* Takes a seperated value string and makes it an array
* @param $delimiter string The delimiter to be seperated by, usually a comma or tab
* @param $string string The string to seperate
* @return array The resulting array
*/
public function svToArray ($delimiter, $string) {
$x = 0;
$rowList = array();
$splitContent = preg_split("#\n+#", trim($string));
foreach ($splitContent as $key => $value) {
$newData = preg_split("#".$delimiter."#", $value);
if ($x == 0) {
$headerValues = array_values($newData);
} else {
$tempRow = array();
foreach ($newData as $rowColumnKey => $rowColumnValue) {
$tempRow[$headerValues[$rowColumnKey]] = $rowColumnValue;
}
$rowList[] = $tempRow;
}
$x++;
}
return $rowList;
}
UPDATE: 错误报告已启用。我使用的文件只有130KB在1500线开始,它做同样的事情...
当我添加调试代码,如下面的例子什么,除非我把一个出口echo "test<br/>";
public function svToArray ($delimiter, $string) {
$x = 0;
$rowList = array();
$splitContent = preg_split("#\n+#", trim($string));
echo "test<br/>";
foreach ($splitContent as $key => $value) {
$newData = preg_split("#".$delimiter."#", $value);
if ($x == 0) {
$headerValues = array_values($newData);
} else {
$tempRow = array();
foreach ($newData as $rowColumnKey => $rowColumnValue) {
$tempRow[$headerValues[$rowColumnKey]] = $rowColumnValue;
}
$rowList[] = $tempRow;
}
$x++;
}
echo "test";
$this->tru->debug($rowList);
exit;
return $rowList;
}
UPDATE 如果我注释掉$tempRow[] = $rowColumnValue;
则呼应样样精....
什么是错误信息? 您是否启用了错误报告? – 2010-05-14 14:04:29
最新的错误?检查display_errors是否打开,并将error_reporting设置为E_ALL。 – AlfaTeK 2010-05-14 14:04:54
你有没有用不同的(也许更小的)文件试过你的代码? – nico 2010-05-14 14:05:17