-8

From:

BOBBY,9238123
LOBBY,2312312

Into:

BEGIN:VCARD
VERSION:2.1
N:BOBBY;;;;
FN:BOBBY
TEL;CELL:9238123
END:VCARD

BEGIN:VCARD
VERSION:2.1
N:LOBBY;;;;
FN:LOBBY
TEL;CELL:3423423
END:VCARD

the bobby repeats twice and phone number once This is what I have tried

my code:

foreach(explode("\n", $text) as $line) {
    // I don't know what to do next
}
  • I'm not sure if a for loop with the comment "I don't know what do do next" actually counts as "have tried". – Simon Forsberg Nov 02 '13 at 14:33
  • I agree with @Simon. For an attempt, I'd like to see some echo statements at least. Also, you already know how to explode on newline, so you could explode on comma in an inner loop, perhaps? – halfer Nov 02 '13 at 14:45

1 Answers1

0

You can retrieve the fields of each line using str_getcsv().

http://www.php.net/manual/en/function.str-getcsv.php

Or just explode a second time:

foreach( explode( "\n", $text ) as $line )
{
    $fields = explode( ',', $line );
    var_dump( $fields );
}
feeela
  • 29,399
  • 7
  • 59
  • 71