RE: [PHP] Re: PHP to Excel (csv)
| From: | Timothy J Hitchens | Date: | Tue, 08 Oct 2002 07:07:37 +0000 |
| Subject: | RE: [PHP] Re: PHP to Excel (csv) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119217@lists.php.net to get a copy of this message | ||
If it is in Mysql format why not reimport into a database and write an
export script... that does the work?
Timothy Hitchens (HITCHO)
tim@hitcho.com.au
HITCHO has Spoken!
-----Original Message-----
From: Owen Prime [mailto:owen@noggin.com.au]
Sent: Tuesday, 8 October 2002 4:31 PM
To: php-general@lists.php.net
Subject: [PHP] Re: PHP to Excel (csv)
Check out http://www.wotsit.org for the exact csv specifications
but
here is
a snippit that works for me:
function csv($value) {
if (strstr($value, ",") || strstr($value, "\n") ||
strstr($value, "\r")) {
return "\"" . str_replace("\"",
"\"\"", $value) . "\"";
} else {
return $value;
}
}
Run this function on each value then implode them with a comma and put a
\n
at the end.
Cheers,
Owen Prime
http://www.noggin.com.au
Ivo Stoykov wrote:
> Hi
>
> I have following problem.
>
> Some data retreived from mysql db I need to send to the user as a
> *.csv file. Usually I separate fields (usually double quoted) with
> comma (,) or semicolomn (;) and the records with cr/lf (Windows) It
> works fin until I do not have cr/lf in any of the fields.
>
> Unfortunately the last field is TEXT type and may have more that one
> cr/lf inside (as data). When this is the case the *,csv file cannot be
> open correctly in Excel. If there are cr/lf in any field it is split
> in Excel as a separate row and the record structure is broken.\
>
> Any idea how could solve this? Thank you
>
> Ivo
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php