Greetings all--
I'm using php to create an Excel spreadsheet from a database table values. I've done this many times, but this time tabs and newlines in the database cell values are causing me grief. Is there a way to quote the database cell data so newlines and tabs within the data are not interpreted by my php code as signals to start a new column-cell or a newline, respectively?

I have :

$rowData .= $cell-1 . "\t" . $cell-2 . "\t" . $cell-3 // and so on.

if any of the $cell-?'s have a tab or a newline in them, I get unwanted results. I'd like not to have to remove the tabs and newlines in the cell data, unless I must.

Thanks for any tips.

    You could do something like:

    function safe($text) {
        $search = array("\t", "\r", "\n");
        $replace = array('\\t', '\\r', '\\n');
    
    return str_replace($search, $replace, $text);
    }

    and then use that function in-line to filter the data.

      Write a Reply...