tags:

views:

26

answers:

1
$lineArray = preg_split('/\t\s*(?=([^"]*"[^"]*")*[^"]*$)/', $line);

Above code snippet it to split a tab delimited file where tabs are not inside double quotes. It works fine except the cases where there double tabs (missing fields). Basically PHP sees only one tab when there are two. Is there a tab-width option?

+1  A: 

The \s will also match a tab and you apparently don't want that.

$lineArray = preg_split('/\t[ \r\n]*(?=([^"]*"[^"]*")*[^"]*$)/', $line);

should fix this problem by only matching non-tab whitespace.

mvds