Script dies, I'm not sure why
Posted
by Webnet
on Stack Overflow
See other posts from Stack Overflow
or by Webnet
Published on 2010-05-14T14:02:44Z
Indexed on
2010/05/14
14:04 UTC
Read the original article
Hit count: 101
php
I'm trying to parse a 6,000 line 500 KB file into an array so I can import the data into our system. The problem is that the script stops executing somewhere between lines 3000-4000. There are no breaks in the code, we use it on other imports. Any ideas on why this might be happening and what I can do to prevent it?
/**
* 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;
}
© Stack Overflow or respective owner