*** Backup Mirror *** The web interface and JSON api for the ConnectedHumber Air Quality Monitoring Project. https://github.com/ConnectedHumber/Air-Quality-Web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Air-Quality-Web/lib/SBRL/ResponseEncoder.php

31 lines
623 B

<?php
namespace SBRL;
/**
* Serialises an object to a variety of formats.
*/
class ResponseEncoder
{
/**
* Encodes an array of associative arrays to CSV.
* @param array $data The data to encode.
* @return string The data encoded to csv.
*/
public static function encode_csv($data) {
if(empty($data))
return "";
$result = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
fputcsv($result, array_keys($data[0]));
foreach($data as $row)
fputcsv($result, array_values($row));
rewind($result);
$response = \stream_get_contents($result);
fclose($result);
return $response;
}
}