I am using this simple function (taken from here) to export PHP array into simple binary Excel file. Writing binary Excel file was my requirement.
public static function array_to_excel($input)
{
$ret = pack('ssssss', 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
foreach (array_values($input) as $lineNumber => $row)
{
foreach (array_values($row) as $colNumber => $data)
{
if (is_numeric($data))
{
$ret .= pack('sssssd', 0x203, 14, $lineNumber, $colNumber, 0x0, $data);
}
else
{
$len = strlen($data);
$ret .= pack('ssssss', 0x204, 8 + $len, $lineNumber, $colNumber, 0x0, $len) . $data;
}
}
}
$ret .= pack('ss', 0x0A, 0x00);
return $ret;
}
Then to call this is pretty much simple simple:
Model_Utilities::array_to_excel($my_2d_array);
Function itself works great and is super simple to create simple binary PHP file. The problem I have is with UTF-8 characters. I get strange characters like Ä¡ instead of right characters... Is there a way to set character encoding in my to excel function?