morwi
morwi

Reputation: 51

Split one column (string) from csv file into three

This probably was asked millions of times, but I can't find a proper answer, really.

Basically, I have a huge .csv file to download data from and to insert it into a local one. It has 10 columns, and the third one is just a string, which always has the same "type" of string. something like: 123/45K67.

I just want to split it into three columns: 123, 45, K67 and exclude the slash totally.

Sorry for bad formatting, writing from mobile.

Upvotes: 1

Views: 78

Answers (1)

Jose Rojas
Jose Rojas

Reputation: 3520

One way would be:

$array = preg_split( "/(?=K)|\//", $value);

this returns:

array(3) { [0]=> string(3) "123" [1]=> string(2) "45" [2]=> string(3) "K67" }

using lookahead to include the matched character, here further information:

http://www.rexegg.com/regex-lookarounds.html

Upvotes: 1

Related Questions