I am trying to format my mysql data to csv but for some reason when the code gets to physical address the text inside which is multi-lined brakes the output in the csv thus making it non usable. i've tried trim(), strip_tags() on top of the cleanData() function;
function cleanData(&$str)
{
// escape tab characters
$str = preg_replace("/\t/", "\\t", $str);
// escape new lines
$str = preg_replace("/\r?\n/", "\\n", $str);
// convert 't' and 'f' to boolean values
if($str == 't') $str = 'TRUE';
if($str == 'f') $str = 'FALSE';
// force certain number/date formats to be imported as strings
if(preg_match("/^0/", $str) || preg_match("/^\+?\d{8,}$/", $str) || preg_match("/^\d{4}.\d{1,2}.\d{1,2}/", $str)) {
$str = "'$str";
}
// escape fields that include double quotes
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
which is echo'd for download with this code;
array_walk($rows,'cleanData');
$trows = implode(",", $rows)."\n";
echo $trows;
Is there a way to concatenate/combine a multi-lined string into a single line string without jumping through hoops?
The data is being retrieved from mysql table - which i loop through and add to the array:
foreach($row as $data)
{
if($data != '')
//echo $data.'<br>';
$tdata = strip_tags(trim($data));
array_push($rows, $tdata);
//echo $tdata.'<br>';
}
When it hits the physical address field, i am trying to combine/concatenate the string which is normally entered over a few lines, eg:
The Campus
Cnr Main & Sloane Street
Bryanston, Johannesburg
02021 South Africa
I want it as "The Campus Cnr Main & Sloane Street Bryanston Johannesburg 02021 South Africa" or "The Campus \n Cnr Main & Sloane Street\n Bryanston, Johannesburg\n 02021 South Africa"