I've created a tab-delimited export file (product datafeed)... the problem is that the carriage returns are creating a problem for the partner site that I am sending the feed to.
I thought that one of the str_replace functions below would fix, but it is not happening.
$value = str_replace('"', '""', $value);
$value = str_replace('\n', '<br>', $value);
$value = str_replace('\r', '<br>', $value);
$value = '"' . $value . '"' . "\t";
}}
$line .= $value;
}
$data .= trim($line)."\n";
The entire script is below... any help would be greatly appreciated.
Thanks,
Ryan
<? require ("config.inc");
/*****************************************
Write the query, call it, and find the number of fields
/**************************************/
$select = "SELECT name, group_no, name, price, image, category1, category2, category3, option1, option1_value, option2, option2_value, keywords, sale_price, oversized, description FROM scdcart where active='yes'";
$export = mysql_query($select);
$count = mysql_num_fields($export);
/**************************************
Extract field names and write them to the $header
variable
/*****************************************/
$output_header = array('GROUP_NAME', 'LINE_ITEM_CODE', 'LINE_ITEM_NAME', 'LINE_ITEM_LIST_PRICE', 'IMAGE_URL', 'FIRST_LEVEL_DEPARTMENT', 'SECOND_LEVEL_DEPARTMENT', 'THIRD_LEVEL_DEPARTMENT', 'OPTION_TYPE1', 'OPTION_VALUE1', 'OPTION_TYPE2', 'OPTION_VALUE2', 'KEYWORDS', 'SALE_PRICE', 'PER_PRODUCT_SHIPPING', 'GROUP_DESCRIPTION');
for ($i = 0; $i < $count; $i++) {
$header .= $output_header[$i] ."\t";
}
/*****************************************
Extract all data, format it, and assign to the $data
variable
/*****************************************/
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
if ((eregi(".jpg", $value)) OR (eregi(".gif", $value))) {
$value = str_replace('"', '""', $value);
$value = '"http://www.sunfriendlyproducts.com/cart/images/' . $value . '"' . "\t";
} else {
$value = str_replace('"', '""', $value);
$value = str_replace('\n', '<br>', $value);
$value = str_replace('\r', '<br>', $value);
$value = '"' . $value . '"' . "\t";
}}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r", "", $data);
/*****************************************
Set the default message for zero records
/*****************************************/
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
/*****************************************
Set the automatic downloadn section
/*****************************************/
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"altura" . date("Ymd") . ".xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>