Make CSV export compatible with PHP 5.3

This commit is contained in:
Frederic Guillot
2015-11-20 20:39:43 -05:00
parent 4c3e519fa9
commit f119cbd6be
3 changed files with 39 additions and 5 deletions

View File

@@ -93,8 +93,7 @@ class Csv
{
if (! empty($value)) {
$value = trim(strtolower($value));
return $value === '1' || $value{0}
=== 't' ? 1 : 0;
return $value === '1' || $value{0} === 't' ? 1 : 0;
}
return 0;
@@ -164,10 +163,14 @@ class Csv
*/
public function write($filename, array $rows)
{
$file = new SplFileObject($filename, 'w');
$fp = fopen($filename, 'w');
foreach ($rows as $row) {
$file->fputcsv($row, $this->delimiter, $this->enclosure);
if (is_resource($fp)) {
foreach ($rows as $row) {
fputcsv($fp, $row, $this->delimiter, $this->enclosure);
}
fclose($fp);
}
return $this;