0

I know, that there is fgetcsv function which process each row of csv file. but what if I don't have file, but attachment (string?) acquired from email by imap php functions (like imap_fetchstructure, imap_fetchbody, imap_base64...).

is there any simple possibility, or must I process it manually?

2
  • Well you could create a temporary file, obviously. Commented Feb 17, 2013 at 12:31
  • 1
    If you have PHP >= 5.3.0, you could use php.net/manual/de/function.str-getcsv.php Commented Feb 17, 2013 at 12:33

1 Answer 1

3

There's also the str_getcsv function (from PHP >= 5.3)

Sign up to request clarification or add additional context in comments.

2 Comments

what about multiline csv? I tried str_getcsv($attach, ",", "\r\n"). this don't get "\r\n" I think. next tried array_chunk(str_getcsv($attach, ","), 9); but this get last entry from first line and first entry of second line as one character and etc. how do I separate it to rows (multidimensional array) or can I go through in while loop like with mysql_fetch_array?
I solved it $lines = explode("\n", $attach); foreach($lines as $row) { $data = str_getcsv($row); ... } I know it's not clear and maybe like double explode but seems it work for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.