I am using the following code to export mysql data into excel format. I use this line to capitalize the first letter of each word in the results: $line .= ucwords($value);
BUT:
I am getting a very strange result.
if i have a name like:
john doe coming from the results, i get john Doe; but
I did notice that 3 dog bakery comes out as 3 Dog Bakery
its as though the first letter is not getting the ucwords() treatment or something ....
why would I be getting this result.
require_once('../func/auth_func.php');
db_connect();
$select = "SELECT * FROM ContactMaster";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= ucwords($value);
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";