# Problem with php exporting excel

**URL:** <https://forum.kirupa.com/t/problem-with-php-exporting-excel/292186>\
**Category:** programming\
**Created:** [July 11, 2009, 2:13am UTC](https://forum.kirupa.com/t/problem-with-php-exporting-excel/292186 "2009-07-11T02:13:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stii](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stii](https://forum.kirupa.com/u/stii)\
**Post date:** [July 11, 2009, 2:13am UTC](https://forum.kirupa.com/t/problem-with-php-exporting-excel/292186/1 "2009-07-11T02:13:18Z")

</div>

Hi Guys,

I am trying to export mySql data to excel with PHP.  
I want it to be the real excel file, where data is input  
into columns and rows.

so far i found a script online that seems to do the job…  
but it generates weird characters in the excel file

> 

\<?php

function xlsBOF() {  
echo pack(“ssssss”, 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);  
return;  
}

function xlsEOF() {  
echo pack(“ss”, 0x0A, 0x00);  
return;  
}

function xlsWriteNumber($Row, $Col, $Value) {  
echo pack(“sssss”, 0x203, 14, $Row, $Col, 0x0);  
echo pack(“d”, $Value);  
return;  
}

function xlsWriteLabel($Row, $Col, $Value ) {  
$L = strlen($Value);  
echo pack(“ssssss”, 0x204, 8 + $L, $Row, $Col, 0x0, $L);  
echo $Value;  
return;  
}

header(“Pragma: no-cache”);  
header(“Expires: 0”);  
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);  
header(“Content-Type: application/force-download”);  
header(“Content-Type: application/octet-stream”);  
header(“Content-Type: application/download”);  
header( “Content-type: application/vnd.ms-excel; charset=UTF-16LE” );  
header("Content-Disposition: attachment;filename=testing.xls ");  
header(‘Content-Transfer-Encoding: binary’);

xlsBOF();

xlsWriteLabel(0,0,“Testing”);

xlsEOF();  
exit();  
?\>

and the outcome of the excel file is  
[http://img199.imageshack.us/i/hahavck.jpg/](http://img199.imageshack.us/i/hahavck.jpg/)

link to excel file  
[http://sharebee.com/86347736](http://sharebee.com/86347736)

so there’s like funny character in front of the text,  
which i copy and paste in other places it appears blank.  
really no clue what’s causing it.

Please help guys!  
thanks!

Stii.
