Get str_getcsv working on PHP 5.2
This commit is contained in:
parent
ddbce8e139
commit
aaf5ca234c
|
@ -57,7 +57,7 @@ class testDataFileIterator implements Iterator
|
|||
list($testData) = explode('//',$testDataRow);
|
||||
|
||||
// Split data into an array of individual values and a result
|
||||
$dataSet = str_getcsv($testData,',',"'");
|
||||
$dataSet = $this->_getcsv($testData, ',', "'");
|
||||
foreach($dataSet as &$dataValue) {
|
||||
$dataValue = $this->_parseDataValue($dataValue);
|
||||
}
|
||||
|
@ -66,6 +66,25 @@ class testDataFileIterator implements Iterator
|
|||
return $dataSet;
|
||||
}
|
||||
|
||||
private function _getcsv($input, $delimiter, $enclosure)
|
||||
{
|
||||
if (function_exists('str_getcsv')) {
|
||||
return str_getcsv($input, $delimiter, $enclosure);
|
||||
}
|
||||
|
||||
$temp = fopen('php://memory', 'rw');
|
||||
fwrite($temp, $input);
|
||||
rewind($temp);
|
||||
$data = fgetcsv($temp, strlen($input), $delimiter, $enclosure);
|
||||
fclose($temp);
|
||||
|
||||
if ($data === false) {
|
||||
$data = array(null);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function _parseDataValue($dataValue) {
|
||||
// discard any white space
|
||||
$dataValue = trim($dataValue);
|
||||
|
|
Loading…
Reference in New Issue