0

I'm still trying to figure out a way to take into account escaped quotes like "test\";nosplit" or 'test\';nosplit'

So far I have something like this:

preg_split('#(^;)|(;$)|(?<!["\'\\]);#', $str_to_split);

But it's not even working on something as simple as: test; 1; 2; '34;34'; wtvr

I want it to split on these:

    v  v  v        v
test; 1; 2; '34;34'; wtvr

    v  v v            v
test; 1;2; '34\'34;34'; wtvr 

    v  v v            v
test; 1;2; "34\"34;34"; wtvr

    v  v v            v
test; 1;2; '34\"34;34'; wtvr 

    v  v v            v
test; 1;2; "34\'34;34"; wtvr

    v  v v                    v
test; 1;2; "3 4 \' 3  4 ; 3 4"; wtvr

How can I make this work?

qwertymk
  • 34,200
  • 28
  • 121
  • 184

1 Answers1

0

Why not use str_getcsv?

var_dump(str_getcsv("test; 1; 2; '34;34'; wtvr",";","'"));

http://ideone.com/JoFkr7#

aquinas
  • 23,318
  • 5
  • 58
  • 81